[Libwebsockets] interacting with a particular connection on a websocket server

Andy Green andy at warmcat.com
Sat Dec 12 01:36:22 CET 2015

On December 12, 2015 5:01:09 AM GMT+08:00, Mark Goldman <mgoldman at securityevaluators.com> wrote:
>Is it possible to:
>   1.  safely get the websockets instance outside the callback
>       in the server.
>   2.  use the user-data outside the callback
>   3.  request libwebsocket_callback_on_writable() on a server
>I would like to be able to let my server interact with a single
>connected client without calling
>and having logic to decide whats going on in all the
>connections.  Failing that, it would be nice to be able to set a
>flag in a particular connection's user-data to aid that decision
>I've read through the API documentation, but it is not clear if
>I can do this or not, nor is it clear how I would do it if I

Well the missing word is 'multithreaded', I think that's your actual question.

There's a pthreads test server now


...it shows how to make wsi lifetime threadsafe in a simple 'official' way.

The user lock that puts in place protecting wsi coming and going means to track and use individual wsi, all you have to do is process ESTABLISHED and CLOSE to put wsi + user pointer you are interested in on your own user "active wsi" list.

It is safe then in another thread, protected by the lock as shown in pthreads example, to ask for callback when writeable on an individual wsi.


>Libwebsockets mailing list
>Libwebsockets at ml.libwebsockets.org

More information about the Libwebsockets mailing list