Socket.IO客户端库提供“欢迎来到Socket.IO”的消息。

4

一段时间后,我又尝试使用node.js和socket.IO进行工作,但结果并不如预期:

我的设置

  1. Downloaded node.js from github and compiled it on my external webserver running on debian squeeze
  2. Created a directory for the node.js project
  3. Added socket.io locally with npm
  4. Created socketIO_server.js and just added this single line of code:

    var socketIO = require('socket.io').listen(8000);
    
  5. Started the socketIO_server.js and console log says "info - socket.io started"

  6. Opening http://domain.tld:8000 gives the message "welcome to socket.io"

问题

当我尝试访问客户端库(http://domain.tld:8000/socket.io/socket.io.js)时,会显示"welcome to socket.io"的消息,但是控制台日志显示"served static content /socket.io.js"。我不知道这是为什么!我认为是并行运行的nginx服务器造成了这个问题,但是停止服务器并没有改变什么。

感谢您的阅读和帮助!


您当前正在运行哪个版本的 socket.io 和 nodejs(假设为最新版本)? - travis
socket.io 0.9.9,nodejs 0.9.1-pre - HenningCash
我进行了一些调查,但没有找到任何明显的问题。我已经链接到了 socket.io 代码的相关部分。我没有安装 0.9.1-pre 版本,但你可以打开你的 node_modules 目录,并对 socket.io 代码进行一些调查。https://github.com/LearnBoost/socket.io/blob/master/lib/manager.js#L571 - travis
好的,与此同时我做了什么:我在我的虚拟机上安装了node.js/socket.io,并且在提供客户端库时遇到了完全相同的问题。看起来像是一个bug。问题是:我如何应用对node_modules的修改?“npm rebuild socket.io”?我只是更改了“欢迎使用socket.io”的消息,但它仍然显示原始消息。 - HenningCash
看起来你的问题可能与这一行有关,它移除了最初的.on('request')处理程序。https://github.com/LearnBoost/socket.io/blob/master/lib/manager.js#L115 - travis
显示剩余4条评论
2个回答

6
这是由于最近对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

Commit: https://github.com/LearnBoost/socket.io/commit/0d3313f536d0231932dd6617db449a071f5bc03a


当监听端口时无法提供socket.io.js服务。(node 0.9.1-pre, socket.io 0.9.9)

由于最近对node的提交,您不能再剪切事件侦听器。这会导致在尝试访问socket.io.js客户端文件时,socket.io显示欢迎消息,因为原始事件侦听器没有被删除。

示例中断:

var socketIO = require('socket.io').listen(8000);

由于node 0.9.1-pre更改了EventEmitter库中访问监听器的方式,因此这会出现错误。
导致socket.io出现问题的nodejs提交。

使EventEmitter.listeners(event)返回监听器数组的副本而不是数组本身。

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


0

我几天前遇到了这个问题。不得不将socket.io降级到v0.8.7,然后它就正常工作了。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接