Tell the server that the user is no longer online

I am new to node.js and trying to develop group chat using node.js and socket.io. I can do group chat and manage data in the system.

Now the problem with me is offline users who are not connected to the Internet. I have this user's connection thread, and as if I am receiving receiverUserSocket.emit ("sendMsg", data), there is no way to check whether this user received a message or not. Yes, there is a .on event ("disconnect"), but I get a delay of about 30-40 seconds.

Is it possible to indicate that the user to whom we want to send a message is online or offline.

+4
source share
1 answer

The best way is to use heart.at socket. Suppose you are using socket.io.

The heartbeats and the problem with finding a completed connection are well explained here:

Advantage / disadvantage of using heart rate socketio

Keep in mind that you can control heart rate timeout values ​​(thereby causing the disconnect event to appear much faster), as described here:

Managing a heartbeat timeout from a client in socket.io

But this can greatly affect your server.

+4
source

All Articles