[Libwebsockets] Libwebsocket identifying PING packet

Andy Green andy at warmcat.com
Wed Oct 19 10:05:15 CEST 2016


On Wed, 2016-10-19 at 13:17 +0530, techi eth wrote:
> Hi,

Can you let us know what happened about your last problem, "SSL Error"?
 Posting on a mailing list you're inviting a lot of people to read
about your problem.  It'd be nice to fill them in with what happened in
case they ever meet something similar.

> I am running server & one of connected client trying to send ping
> packet.I need to identify that packet & response pong.
> 
> How to identify ping packet on web socket callback ?
> 
> I understand we can write PONG by using LWS_WRITE_PONG in response of
> Ping.

Lws automatically sends a PONG when it receives a PING.  It's not
passed through to the user code.

What goes in the PONG is mandated to be exactly the the PING payload
returned and nothing else.

If you are looking for dead connection detection, in 2.1 and later
there is this in the context creation info that provides it
automatically

	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


> 
> _______________________________________________
> Libwebsockets mailing list
> Libwebsockets at ml.libwebsockets.org
> http://libwebsockets.org/mailman/listinfo/libwebsockets



More information about the Libwebsockets mailing list