'libwebsockets: How to close connection

I’m using libwebsockets to run both a websocket server and a client (actually in the same executable). Is there a way to gracefully close a connection?

I know I can return a negative int in my callback function to make the connection abort, but that feels more like something that happens on an error. In some example code on some random blog, I found a reference to a function libwebsocket_close_and_free_session but that does not exist (any longer?) in the library code.

Ideally, I would like to be able to close a different connection from within the callback handler than the one being called (i.e. to interpret a command like “close the other connection”).



Solution 1:[1]

I suppose you are looking for a function lws_set_timeout( wsi, reason, timeout ) .

The timeout can be also LWS_TO_KILL_SYNC for immediate close the session.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 PKP