[Libwebsockets] Terminating a connection

Andy Green andy at warmcat.com
Sat May 21 03:46:20 CEST 2016



On 05/21/2016 09:14 AM, Ian Armstrong wrote:
> I have a server running lib web sockets. When a client connects the
> server reads the get request and decides if it will allow the connection
> or not. To reject the connection I return -1 from the call back. This
> works fine.
>
> My question is, if for some other reason later on, I wish to terminate
> the connection how do I do this? I have checked the api docs and tried a
> few random things but cannot find a solution.

If the "some reason" that makes you want to terminate the connection is 
coming inside the callback, there's no problem just return -1 in RECEIVE 
or whatever.

If the reason is external, you can either engineer a callback when 
writable and see that you want to close it there, or use 
lws_set_timeout() to set the timeout on the connection to -1 which will 
synchronously close it when the timeouts are checked once a second by 
the library.

If the "some reason" is itself a timeout, you can also use the lws 
timeouts system from the user callback with lws_set_timeout() to get 
that taken care of automatically.

-Andy

> Ian
>
> *Ian Armstrong
> *Principal Academic Staff Member
> Wellington Institute of Technology
> Private Bag 39803, Lower Hutt 5045
> Wellington, New Zealand
>
> *P * +64 4 830 3055
> *E *_ian.armstrong at weltec.ac.nz_
> *W *http://www.weltec.ac.nz
>
> Resuts: https://results.weltec.ac.nz
> Timetables: http://timetable.weltec.ac.nz
> Course Material: https://soit.weltec.ac.nz
>
> Description: cid:image001.gif at 01CB0CA4.E4A2DE80
>
>
>
> _______________________________________________
> Libwebsockets mailing list
> Libwebsockets at ml.libwebsockets.org
> http://libwebsockets.org/mailman/listinfo/libwebsockets
>



More information about the Libwebsockets mailing list