开发者

info - unhandled socket.io url

开发者 https://www.devze.com 2023-03-28 10:43 出处:网络
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

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


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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号