Socket.IO client library gives “welcome to socket.io” message

前端 未结 2 490
醉酒成梦
醉酒成梦 2021-01-06 03:37

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

My setup

  1. Downloaded node.js from github and compil
2条回答
  •  清酒与你
    2021-01-06 04:09

    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

    UPDATE

    This issue has been fixed as of 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


    Can not serve socket.io.js when listening on port. (node 0.9.1-pre, socket.io 0.9.9)

    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.

    Example breakage:

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

    This breaks due to the way node 0.9.1-pre changed the way you can access listeners for the EventEmitter lib.

    nodejs commit that breaks socket.io

    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

    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

提交回复
热议问题