[Libwebsockets] How to close the ws connection properly

Kun Zhao kunzhao77 at gmail.com
Fri Jul 20 15:42:05 CEST 2018


This question is very prompt. I'm just about to ask how to close a client
WebSocket connection. Is this the same way to close a client connection? I
have one context serving multiple client connections.

Thanks,
Kun

On Wed, Jul 18, 2018 at 4:52 PM Brice Hamon <brice at ydotm.com> wrote:

> 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
>>
>>
> _______________________________________________
> 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/20180720/6bbd0550/attachment-0002.html>


More information about the Libwebsockets mailing list