Socket.IO 客户端库提供“欢迎使用 socket.io";信息 [英] Socket.IO client library gives "welcome to socket.io" message
问题描述
一段时间后,我再次尝试使用 node.js 和 socket.IO,但没有按预期工作:
After some time I tried working with node.js and socket.IO again, but it didn't work as expected:
- 从 github 下载 node.js 并在我的 外部网络服务器 上编译它,该服务器在 debian 挤压上运行
- 为 node.js 项目创建一个目录
- 使用 npm 在本地添加 socket.io
创建了 socketIO_server.js 并添加了这行代码:
- Downloaded node.js from github and compiled it on my external webserver running on debian squeeze
- Created a directory for the node.js project
- Added socket.io locally with npm
Created socketIO_server.js and just added this single line of code:
var socketIO = require('socket.io').listen(8000);
启动socketIO_server.js,控制台日志显示信息-socket.io已启动"
Started the socketIO_server.js and console log says "info - socket.io started"
问题
当我尝试通过 http://domain.tld 访问客户端库时:8000/socket.io/socket.io.js 它还给出了消息欢迎使用 socket.io",但控制台日志显示提供静态内容/socket.io.js".我不知道为什么会这样!我虽然并行运行的 nginx 服务器导致了这个问题,但停止服务器并没有改变任何东西.
The Problem
When I try to access the client library by http://domain.tld:8000/socket.io/socket.io.js it gives also the message "welcome to socket.io", but the console log shows "served static content /socket.io.js". I have no idea why this happens! I though the nginx server running parallel causes this problem but stopping the server didn't change anything.
感谢阅读和帮助!
推荐答案
这是由于在最近的更改中对 nodejs 的 EventEmitter 库所做的提交造成的.我在 socket.io 上打开了一个问题.
This is caused by a commit made to the EventEmitter lib of nodejs in a recent change. I've opened an issue on socket.io.
https://github.com/LearnBoost/socket.io/issues/987
更新
此问题已从 socket.io 0.9.12 开始修复
This issue has been fixed as of socket.io 0.9.12
修复:https://github.com/LearnBoost/socket.io/blob/0.9.12/lib/manager.js#L116
提交:https://github.com/LearnBoost/socket.io/commit/0d3313f536d204d023f536d04d025c5301a
侦听端口时无法提供 socket.io.js.(节点 0.9.1-pre,socket.io 0.9.9)
由于最近对 node 的提交,您不能再拼接事件侦听器.这会导致 socket.io 在尝试访问 socket.io.js 客户端文件时显示欢迎消息,因为原始事件侦听器没有被删除.
Due to a recent commit to node, you can no longer splice out event listeners. This causes socket.io to display the welcome message when trying to access the socket.io.js client file as the original event listener does not get removed.
破损示例:
var socketIO = require('socket.io').listen(8000);
由于节点 0.9.1-pre 改变了您访问 EventEmitter 库的侦听器的方式,这会中断.
This breaks due to the way node 0.9.1-pre changed the way you can access listeners for the EventEmitter lib.
nodejs 提交破坏 socket.io
nodejs commit that breaks socket.io
让 EventEmitter.listeners(event) 返回一个 listeners 数组的副本数组本身.
Make EventEmitter.listeners(event) return a copy of the listeners array instead of the array itself.
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代码:
Relative socket.io code:
// reset listeners
this.oldListeners = server.listeners('request').splice(0);
https://github.com/LearnBoost/socket.io/blob/master/lib/manager.js#L115
这篇关于Socket.IO 客户端库提供“欢迎使用 socket.io";信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!