Get connection status on Socket.io client

后端 未结 5 1792
被撕碎了的回忆
被撕碎了的回忆 2020-12-23 10:50

I\'m using Socket.io, and I\'d like to know the status of connection to the server from the client-side.

Something like this:

socket.status // return         


        
5条回答
  •  萌比男神i
    2020-12-23 11:47

    These days, socket.on('connect', ...) is not working for me. I use the below code to check at 1st connecting.

    if (socket.connected)
      console.log('socket.io is connected.')
    

    and use this code when reconnected.

    socket.on('reconnect', ()=>{
      //Your Code Here
    });
    

提交回复
热议问题