socket.on('connection' … event never fired nodejs + express + socket.io

前端 未结 3 718
遥遥无期
遥遥无期 2020-12-29 09:15

Problem socket.io NOT working

Details

  • Generated a project with express [folder]; cd [folder]; npm install;
3条回答
  •  星月不相逢
    2020-12-29 09:43

    Ricardo Tomasi is correct, saved my life, i was going crazy.

    Altough things changed, we are in 2013, there's still an issue opened (since 2 years) on this

    probably something changed, anyway to register the 'connect' event i had to do this:

    var openSocket = function (uniqueID) {
      var appSocket = io.connect('/'+uniqueID, { transports: ['websocket', 'xhr-polling']});
      appSocket.socket.on('connect', function () {
        console.log('i did connect.');
      });
      return appSocket;
    };
    

提交回复
热议问题