过了一段时间后,我再次尝试使用node.js和socket.IO,但它没有像预期的那样工作:
我的圈套
问题
当我试图通过http://domain.tld:8000/socket.io/socket.io.js访问客户端库时,它也给出了“欢迎来到socket.io”的消息,但是控制台日志显示了“服务静态内容/socket.io.js”。我不知道为什么会这样!我认为运行并行的nginx服务器会导致这个问题,但是停止服务器并没有改变任何事情。
感谢您的阅读和帮助!
发布于 2012-08-09 21:25:33
这是由于在最近的更改中对nodejs的EventEmitter库进行了提交。我在socket.io上打开了一个问题。
https://github.com/LearnBoost/socket.io/issues/987
更新
这一问题已在socket.io 0.9.12中得到解决。
Fix:https://github.com/LearnBoost/socket.io/blob/0.9.12/lib/manager.js#L116
提交:https://github.com/LearnBoost/socket.io/commit/0d3313f536d0231932dd6617db449a071f5bc03a
在监听端口时不能为socket.io.js提供服务。(节点0.91.PRE,socket.io 0.9.9)
由于最近提交到节点,您不能再连接事件侦听器。这将导致socket.io在尝试访问socket.io.js客户端文件时显示欢迎消息,因为原始事件侦听器不会被删除。
例如破损:
var socketIO = require('socket.io').listen(8000);由于节点0.9.1-pre改变了您访问EventEmitter库的侦听器的方式,这就中断了。
破坏socket.io的nodejs提交
让EventEmitter.listeners(事件)返回侦听器数组的副本,而不是数组本身。
EventEmitter.prototype.listeners = function(type) {
if (!isArray(this._events[type])) {
this._events[type] = [this._events[type]];
}
- return this._events[type];
+ return this._events[type].slice(0);
};https://github.com/joyent/node/commit/20e12e4be37f394672c001fdb9b05c0275731901#L1R245
相对socket.io代码:
// reset listeners
this.oldListeners = server.listeners('request').splice(0);https://github.com/LearnBoost/socket.io/blob/master/lib/manager.js#L115
发布于 2012-08-21 19:51:09
几天前我遇到了这个问题。不得不将socket.io降至0.8.7,而且效果很好。
https://stackoverflow.com/questions/11889132
复制相似问题