Socket IO reconnect?

前端 未结 5 1636
终归单人心
终归单人心 2020-12-12 19:06

How to reconnect to socket io once disconnect has been called?

Here\'s the code

function initSocket(__bool){                    
    if(         


        
5条回答
  •  -上瘾入骨i
    2020-12-12 19:51

    This is an old question, but I was struggling with this recently and stumbled here. Most recent versions of socket.io (>2.0) doesn't have the socket.socket property anymore as pointed out here.

    I am using socket.io-client 2.2.0 and I was facing a situation where the socket seems to be connected (property socket.connected = true) but it wasn't communicating with the server.

    So, to fix that, my solution was call socket.close()and socket.open. These commands force a disconnection and a new connection.

提交回复
热议问题