info - unhandled socket.io url

前端 未结 1 703
难免孤独
难免孤独 2021-01-14 03:19

I working on a socket.io + node project. Just like in this page, http://davidwalsh.name/websocket I am getting \"info - unhandled socket.io url\" error in socket.io v7. But

相关标签:
1条回答
  • 2021-01-14 04:07

    Had the exact issue couple of days back and looks like socket.io had some changes in the API.

    I have a working demo of socket.io sending and receiving a message - uploaded to https://github.com/parj/node-websocket-demo as a reference

    Essentially two changes

    1. On Server side - changed socket.on to socket.sockets.on

      var socket = io.listen(server);
      socket.sockets.on('connection', function(client)  
      
    2. On Client side - URL and port not required as it is autodetected.

      var socket = io.connect();
      

    NOTE: you can also io.connect("http://<ip>:<port>") on the client side, however, not required anymore as it is autodetected

    Here are the exact changes - https://github.com/parj/node-websocket-demo/commit/5ba52db9d1a5b7e8a3af5839adcd12768741dc97

    This has been tested using Express 2.5.2 and Socket.io 0.8.7

    0 讨论(0)
提交回复
热议问题