websocketpp icon indicating copy to clipboard operation
websocketpp copied to clipboard

Internet disconnection on the client side

Open Nitya05 opened this issue 7 years ago • 2 comments

Is there a way for the client to know that the internet on its side has got disconnected, so that it should stop sending data to the server and in turn, try to create a new connection with the server as soon as the internet is connected again.

In cases, where there is no internet, the on_fail() / on_close() api(s) do not get triggered, and hence the client continues to send data.

Are there any heartbeat or keepalive messages that can be used to check if the internet connection is still on?

Nitya05 avatar Dec 19 '17 06:12 Nitya05

I have the same problem.

I don't know how to detect when the websocket connection has been lost due to a disconnection of the network cable for example.

I would need some way to do this check also with websocket connection.

ErYcKsg avatar Dec 19 '17 08:12 ErYcKsg

you'll generally need to write some data to the socket in order to detect a disconnect. The WebSocket protocol has a ping message that you can send that can be used to detect liveness without transmitting any data messages.

In WebSocket++ you can send pings with connection::ping. The results will come either as a close handler resulting from the TCP bad pipe or you can register a pong timeout handler that will let you know as soon as the expected reply from the other end is late (for whatever definition of late that you configure)

zaphoyd avatar Dec 19 '17 15:12 zaphoyd