[Libwebsockets] How to close the ws connection properly

Brice Hamon brice at ydotm.com
Wed Jul 18 23:51:01 CEST 2018


Yes that is correct.
Trigger a writeable event on your wsi, then on write return -1.
You are doing it correctly.

On Wed, Jul 18, 2018 at 4:04 AM, Chropin Hu <chropinhu at gmail.com> wrote:

> Dear All,
>        How to close the ws connection from the server side?
>        currently, I just call the following funtion at stand alone thread,
>                    lws_close_reason(g_wsi_test_close,
> LWS_CLOSE_STATUS_NORMAL,
> (unsigned char *)"seeya", 5);
>    lws_callback_on_writable(g_wsi_test_close);
>
>         then, handle LWS_CALLBACK_SERVER_WRITEABLE msg like this,
>                case LWS_CALLBACK_SERVER_WRITEABLE:
> case LWS_CALLBACK_HTTP_WRITEABLE:
> {
> if (lws_get_close_length(wsi))
> {
> return -1;
> }
> }
>       It` seems work well,  the connection closed. but I am not sure for
> this.
>       are there other ways to close the ws connection from the server side?
>
> Best Wishes,
> Chropin.
>
>
> _______________________________________________
> Libwebsockets mailing list
> Libwebsockets at ml.libwebsockets.org
> https://libwebsockets.org/mailman/listinfo/libwebsockets
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://libwebsockets.org/pipermail/libwebsockets/attachments/20180718/e764972a/attachment-0002.html>


More information about the Libwebsockets mailing list