[Libwebsockets] Prevent client from establishing WS connection too quickly

Andy Green andy at warmcat.com
Fri Sep 25 11:26:21 CEST 2020


 > I'm using version 4.1 of lws as a ws server. To ensure only one 
connection, lws is made to kick out the old connection if a similar 
connection arrives.

 > Is it possible to delay the handshake to like 5 seconds?

There should be some way to ratelimit it at iptables, but IIUI your 
existing arrangements almost do what you want... you just need to defer 
the close of the existing connection for 5s.  Set a pss flag to say it's 
dead, so you stop sending and ignore rx, along with an lws_sul scheduled 
event for +5s.  When the event comes, close the old wsi there using, eg

  lws_wsi_close(wsi, LWS_TO_KILL_ASYNC);

The other peer doesn't see his connection is gone for 6s then.

-Andy


More information about the Libwebsockets mailing list