info - unhandled socket.io url

2019-02-18 22:16发布

问题:

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 I dont get this error with v6.17? Do you have any idea with this error?

Thanks

回答1:

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