warmcat / libwebsockets

canonical libwebsockets.org networking library
https://libwebsockets.org
Other
4.77k stars 1.49k forks source link

How to close one of multiple connections as a client #1471

Closed linuxvae closed 5 years ago

linuxvae commented 5 years ago

hello sir, I use libwebsockets as a client to connect to the server, use function "lws_client_connect_via_info" to create connection, will use multiple connections to connect to the server, I want to use the same context, now ,how do I actively close one of the connections? I looked for the source code and the examples, and did not actively close the interface of a single connection, only the interface that destroys the context: “lws_context_destroy”. thanks

lws-team commented 5 years ago

Normally connections close either because the underlying network connection closed from the other side, or they decide themselves to close because they finished what they're doing.

But as you describe sometimes you might want to make them close. If you have the wsi, you can use the timeout api to have the wsi close and do normal close processing. But it must be called from the service thread.

https://libwebsockets.org/git/libwebsockets/tree/include/libwebsockets/lws-timeout-timer.h#n79-105