Socket IO detect when client has lost connection

前端 未结 2 1395
北恋
北恋 2021-02-19 23:41

I need to be able to detect when a user has lost connection to the socket, it doesn\'t seem that socket.on(\"disconnect\") is being called when I just close my lapt

2条回答
  •  北海茫月
    2021-02-19 23:53

    As mentioned here https://github.com/LearnBoost/Socket.IO/wiki/Configuring-Socket.IO, Socket.IO has it's own heartbeat implementation. But the defaults are a 25s interval and a 60s threshold for a lost connection.

    So my advice: Set the defaults as you expect on testing. Otherwise you may miss the threshold.

    Example:

    socket.set("heartbeat timeout", 10);
    socket.set("heartbeat interval", 5);
    

提交回复
热议问题