-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Lost connection detection
Lost connection detection (I know Germans come up with the best names!) is a feature to detect if a connection to a another endpoint is lost e.g. due to losing wifi or mobile data signal.
For detection a lost connection we use a heartbeat implementation.
The detection works as following:
Your endpoint (e.g. server) is sending a ping to the connected endpoints (e.g. clients) in a specific interval (default: 60 seconds).
In the next interval the server first checks if he recieved a pong response from the client.
If this is the case, it will send a new ping to the client.
If this is not the case, it will close the connection to the client assuming the connection got lost!
The detection works both ways, so the client is also able to detect a lost connection to the server.
This feature takes advantage of the specification in section 5.5.2 that a endpoint SHOULD respond to a Ping frame with Pong frame as soon as is practical.
The method to change the interval is setConnectionLostTimeout()
, both for the server and the client.
To change the check interval, simple use the method setConnectionLostTimeout()
and set your check interval in seconds
For example if you want to change the interval to 30 seconds use the following code.
ChatServer s = new ChatServer( port );
s.setConnectionLostTimeout( 30 );
s.start();
A value lower or equal 0 results in the check to be deactivated.
ChatServer s = new ChatServer( port );
s.setConnectionLostTimeout( 0 );
s.start();