Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Socket IO detect when client has lost connection

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 laptop, so it doesn't run the ajax call that needs to run in order to update the database to mark the user as offline. How could I check if the connection has been closed or whatever?

like image 935
Dylan Cross Avatar asked Feb 07 '12 19:02

Dylan Cross


1 Answers

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);
like image 158
sja Avatar answered Oct 24 '22 11:10

sja