[Libwebsockets] How to maintain a list of online clients ?

Andy Green andy at warmcat.com
Sun Oct 23 18:08:03 CEST 2016



On October 24, 2016 12:01:11 AM GMT+08:00, hanguofu <hanguofu at 163.com> wrote:
>I thought this question had been asked before , but I still want to
>confirm it :
>
>
>I am developing  server and client applications with libwebsocket at
>both sides.  I would like to maintain a list of all of the online
>clients at the server side so that the server can talk to a  client
>which has been silent and still online. Are LWS_CALLBACK_ESTABLISHED
>and  LWS_CALLBACK_CLOSED enough to maintain such information ? Is tcp
>keepalive a must  to achieve this goal ?

If all you want to do is confirm every established ws client connection is still alive, lws can do it for you in v2.1 and later.  You can set this in the context creation info struct:

unsigned short ws_ping_pong_interval;
	/**< CONTEXT: 0 for none, else interval in seconds between sending
	 * PINGs on idle websocket connections.  When the PING is sent,
	 * the PONG must come within the normal timeout_secs timeout period
	 * or the connection will be dropped.
	 * Any RX or TX traffic on the connection restarts the interval timer,
	 * so a connection which always sends or receives something at intervals
	 * less than the interval given here will never send PINGs / expect
	 * PONGs.  Conversely as soon as the ws connection is established, an
	 * idle connection will do the PING / PONG roundtrip as soon as
	 * ws_ping_pong_interval seconds has passed without traffic
	 */

-Andy

>
>Regards !
>
>
>Guofu Han   
>
>------------------------------------------------------------------------
>
>_______________________________________________
>Libwebsockets mailing list
>Libwebsockets at ml.libwebsockets.org
>http://libwebsockets.org/mailman/listinfo/libwebsockets




More information about the Libwebsockets mailing list