In this case, there are a few things to consider:
Determine that the application is disabled / enabled
See: Online and offline events .
When your application detects an online event after waking up the computer, you can get any information that you missed.
For older web browsers, you need to do this in a smarter way. At Pusher, we added ping-pong checks between the client and server. If the client does not receive ping for a certain period of time, he knows that there is a connection problem. If the server sends ping and does not receive pong back with a certain time, it knows what the problem is.
The ping-pong mechanism is defined in the specification , but the method of sending a ping or pong has not been defined in the WebSocket API as yet.
Getting Lost Information
Most real-time servers only deliver messages for connecting to clients. If the client is not connected, perhaps due to a temporary network outage or their computer is sleeping for a while, then these clients will skip the message.
Some structures provide access to messages through history / cache. For those who do not need this, you will need to detect the problem (as indicated above) and then receive any missed messages. A good way to do this is to provide a timestamp or sequence identifier with each message so that you can call your web server to say “give me all messages with X”.
source share