Muhammed Almaz Muhammed Almaz - 1 year ago 116
Node.js Question when client Internet going to off

How can i callback from client to server internet going to off? I have users and i added their connections in the some room. But I can not know when they are Internet going to down. I want to callback their statues but I do not know how. My clients are android phone.

this function does not work.

socket.on("disconnect", function () {
var SocketRoom=;

Answer Source

The clients can't send a message through the socket connection, if they are not connected to the network/internet anymore. You might want to check for timeouts.

Once a client connects to the server, the server sends a message to the client in a fixed time interval (like every 5 seconds). If the client responds to that message, you know, it's still conencted and continue with your program logic. If the client does not respond to your message, then they are very likely not connected to the internet anymore (or are unreachable for other reasons). If this is the case, you can force them to leave the room (like in your socket.on("disconnect", ...) function).

Please note:

  • The higher the timeout interval, the less precise is the actual disconnect time, but the load on the connection is kept low.
  • If a client does not respond to a timeout-check, you might want to retry to send a message to that client a couple of times before force-closing the connection.
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download