[Libwebsockets] Libwebsocket identifying PING packet

Andy Green andy at warmcat.com
Wed Oct 19 11:28:16 CEST 2016


On Wed, 2016-10-19 at 14:37 +0530, techi eth wrote:
> Hi,
> 
> Sorry for not updating on SSL issue.I am still analyzing issue by
> using wireshark.
> Only problem is i am not able to reproduce the same issue.I have seen
> the same once with my test application.

Dunno.  Basically it sounds like something entirely in the SSL domain,
that can still be an lws problem but there would need to be some reason
to think that.

If it only happened once maybe just the connection was reset by an
intermediary or the client countermanded / cancelled the connection
partway through.

> Regarding PING/Pong interval I understand setting interval to defined
> value will result in my test client/server will do ping on connection
> & expect pong within defined interval.
> 
> On other side if i have set this as zero & if other client/server
> will send PING than in this case lws will automatically reply Pong Or
> it expect application to do the same ?

 - Lws will always send back a matching PONG on receipt of the PING,
next time the connection is writeable.  You don't have to do anything
to enable that behaviour.  It's part of the ws protocol and there's
never any reason to not do it, so lws always takes care of it.

 - If one side sent a PING manually, it can look for the PONG callback,
one of

   LWS_CALLBACK_RECEIVE_PONG
   LWS_CALLBACK_CLIENT_RECEIVE_PONG

if and when the PONG arrives.  So you can always send a ping in the
user code and be aware if and when the PONG came in user code.

 - The context option for generating PINGs if the connection has been
idle for long enough and then dropping the connection if the expected
PONG isn't coming quick enough is optional, and defaults to disabled.

-Andy

> Thanks
> 
> On Wed, Oct 19, 2016 at 1:35 PM, Andy Green <andy at warmcat.com> wrote:
> > 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