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

浏览器端
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=1420622609420
StatusCode:400BadRequest
服务器返回的错误信息是:{"code":0,"message":"Transportunknown"}
这是什么情况?求大神解答~~~
白猪掌柜的
浏览 343回答 2
2回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript