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

Andy Green andy at warmcat.com
Mon Oct 24 19:59:35 CEST 2016



On October 24, 2016 11:57:55 PM GMT+08:00, hanguofu <hanguofu at 163.com> wrote:
>Hi , Andy :
>
>
>Great ! I like this feature :)
>
>
>Do you mean server application will be informed of the dropped
>connection at case LWS_CALLBACK_CLOSED if client is disconnected at the
>ping-pong interval ?

Yes, if no PONG is coming it's the same as any other timeout being triggered, and it goes through the normal close processing including callbacks.  ("Normal close processing for failing a timeout" is a little different only in that lws will skip trying to attempt any more socket activity like doing the ws close handshake, since failing the timeout implies communication is broken.)

>Please allow me to express my gratitude to your constant contribution
>to this great project !

You're welcome ^^

-Andy

>
>Cheer !
>
>
>
>
>Guofu Han
>
>
>
>
>
>At 2016-10-24 00:08:03, "Andy Green" <andy at warmcat.com> wrote:
>>
>>
>>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
>>
>
>
>------------------------------------------------------------------------
>
>_______________________________________________
>Libwebsockets mailing list
>Libwebsockets at ml.libwebsockets.org
>http://libwebsockets.org/mailman/listinfo/libwebsockets




More information about the Libwebsockets mailing list