为什么socket.io现在在express.io上显示500 (内部服务器错误)??
客户端:
$(document).ready(function(){
$.getScript("http://www.mysite.com:8000/socket.io/socket.io.js",function(){
var socket = io.connect('http://www.mysite.com:8000'); //<<--error
socket.emit('ready');
});});服务器端:
var express = require('express.io')
, engine = express().http().io();
engine.use(express.cookieParser());
engine.use(express.session({secret:'monkey'}));
engine.all('/',function(req,res,next){res.header("Access-Control-Allow-Origin","*");res.header("Access-Control-Allow-Headers","X-Requested-With");next();});
engine.get('/', function(req, res) {
req.session.loginDate = new Date().toString()
res.sendfile(__dirname)
});
engine.listen(8000);
engine.io.route('ready',function(socket){console.log('hellooooooooooo');});我正在遵循https://github.com/techpines/express.io上的文档,我只更改了两件事:跨域和应用程序被称为引擎。我就是看不出问题所在,还有没有人能让它工作呢?
注意:它使用的不是express.js,而是express.io (与socket.io更兼容)
这就像是,即使engine = express().http().io();io为socket.io,socket.io也没有在服务器上监听
发布于 2013-04-30 19:02:10
我遇到了类似的问题,但我通过在express.io示例代码中复制和粘贴代码示例来修复它,并且它起作用了。然后我对它们进行了比较,以检查问题可能是什么,并观察到代码的顺序很重要。
此顺序会导致错误:
但是,当我遵循示例代码中提供的代码时,我发现这个顺序是有效的:
希望这也能对你有所帮助。
发布于 2014-03-04 14:05:52
我相信上面的示例是失败的,因为您使用的是res.sendfile(__dirname)调用,而没有提供文件名。
这是来自express.io的,注意它使用了res.sendfile(__dirname + '/client.html')
express = require('express.io')
app = express().http().io()
// Setup your sessions, just like normal.
app.use(express.cookieParser())
app.use(express.session({secret: 'monkey'}))
// Session is automatically setup on initial request.
app.get('/', function(req, res) {
req.session.loginDate = new Date().toString()
res.sendfile(__dirname + '/client.html')
})https://stackoverflow.com/questions/16269182
复制相似问题