Keep-Alive Mechanism

Usually the jWebSocket Server terminates a session after a configurable amount of time of user inactivity. Because the server cannot register a hard shutdown of a client a timeout management for the session can hardly be avoided. This could be the case if the client process simply gets killed w/o giving the client a chance to send a close token to the server or if the connection gets lost e.g. due to network issues. If there was no timeout management the server would run out of ports and not accept further connections after a certain amount of time.

For streaming applications the user may not type anything for a longer time but just look what happens. For this case the client can send so called keep-alive pings to the server in certain configurable intervals. The server then detects that the client is still alive and does not terminate the connection. Optionally the server can even send an acknowledge back to the client, so that also the client knows that the server is still working properly.

Both on the server and the client side the keep-alive functionality is implemented in the System plug-in.

Keep-Alive Plug-In on the server

For the server the jWebSocket project provides the org.jWebSocket.plugins.System class. It implements the ping token handling. For details please refer to the Token Reference.

Keep-Alive Plug-In on the JavaScript client

On the JavaScript client the System plug-in provides the two methods startKeepAlive and stopKeepAlive.

Publications

Learn more about WebSockets in general, get background information and gain deeper insight!

Join jWebSocket

Wether developer, designer or translator – join the jWebSocket team and grow together with our success!

Copyright © 2013 Innotrade GmbH. All rights reserved.