Socket.IO客户端库给出“welcome to socket.io”。信息 [英] Socket.IO client library gives "welcome to socket.io" message

查看:126
本文介绍了Socket.IO客户端库给出“welcome to socket.io”。信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一段时间后,我再次尝试使用node.js和socket.IO,但它没有按预期工作:

After some time I tried working with node.js and socket.IO again, but it didn't work as expected:


  1. 从github下载node.js并在我的外部网络服务器上编译并在debian squeeze上运行

  2. 为node.js项目创建了一个目录

  3. 使用npm在本地添加了socket.io

  4. 创建了socketIO_server.js并添加了这一行代码:

  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);


  • 启动socketIO_server.js和控制台日志说info - socket.io started

  • Started the socketIO_server.js and console log says "info - socket.io started"



    问题



    何时我尝试通过 http://domain.tld:8000 / socket访问客户端库.io / socket.io.js 它还给出了welcome to 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 lib的提交引起的。我在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/0d3313f536d0231932dd6617db449a071f5bc03a

    在侦听端口时无法提供socket.io.js。 (节点0.9.1-pre,socket.io 0.9.9)

    由于最近提交节点,您不能再拼接出事件侦听器。这会导致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 lib。

    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


    Make EventEmitter。 listeners(event)返回一个监听器数组的副本,而不是数组本身的

    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客户端库给出“welcome to socket.io”。信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆