为了账号安全,请及时绑定邮箱和手机立即绑定

node.js socket.io 与 express 集成出错

node.js socket.io 与 express 集成出错

白猪掌柜的 2019-04-16 20:27:19
浏览器端varsocket=io.connect('http://localhost:3000');服务器端varexpress=require('express');varroutes=require('./routes/index');varuser=require('./routes/user');varchat=require('./routes/chat');varhttp=require('http');varpath=require('path');varMongoStore=require('connect-mongo')(express);varsettings=require('./settings');varflash=require('connect-flash');varmulter=require('multer');varapp=express();app.set('port',process.env.PORT||3000);app.set('views',path.join(__dirname,'views'));app.set('viewengine','ejs');app.use(flash());app.use(express.favicon());app.use(express.logger('dev'));app.use(express.json());app.use(express.urlencoded());app.use(express.methodOverride());app.use(express.cookieParser());app.use(express.session({secret:settings.cookiesSecret,key:settings.db,cookie:{maxAge:1000*60*60*24*30},store:newMongoStore({db:settings.db})}));app.use(multer({dest:'./public/images/user',rename:function(fieldname,filename){returnfilename;}}));app.use(app.router);app.use(express.static(path.join(__dirname,'public')));app.use(express.static(path.join(__dirname,'bower_components')));if('development'==app.get('env')){app.use(express.errorHandler());}routes(app);varserver=http.createServer(app);vario=require('socket.io')(server);io.on('connection',function(){console.log('connection')});server.listen(app.get('port'),function(){console.log('Expressserverlisteningonport'+app.get('port'));});出错这个错误:RequestURL:http://localhost:3000/socket.io/1/?t=1420622609420StatusCode:400BadRequest服务器返回的错误信息是:{"code":0,"message":"Transportunknown"}这是什么情况?求大神解答~~~
查看完整描述

2 回答

  • 2 回答
  • 0 关注
  • 342 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信