When establishing a web socket connection between client to server the connection can close unexpectedly for several reasons:
- Inactivity on the TCP channel.
- server issue which makes the connection to close.
- Client crash or reload/ refresh.
I am looking for the way of dealing with such situations or, at least, know they occurred.
When reading about WebSocket close, I understood the WebSocket protocol support server initiated pings pongs which can be used for the server to know if a client has crashed. (client initiated ping pong are not supported). - is it the best way to deal with client crash?
Also, I see in spec that on the client side we can listen to the onClose event and that there are several codes to understand why connection has been closed - When the server crashed is that onClose event is always called?