[Libwebsockets] regarding publish -subscribe using libwebsockets

Andy Green andy at warmcat.com
Sun Apr 24 08:33:02 CEST 2016



On April 24, 2016 2:02:55 PM GMT+08:00, "Suman.Patro-TRN" <Suman.Patro-TRN at lntebg.com> wrote:
>Hello,
>
>I am trying to achieve publish -subscribe mechanism using
>libwebsockets.  I have a backend server (tcp) which has pub-sub logic.I
>have integrated my websocket server based on libwebsockets into the 
>backend server on different port to that of the tcp one. My goal is
>whenever a web client subscribes to a specific topic , it should fetch
>data that the tcp client (publisher) pushes based on the same  topic.
>This works fine for a single  web client. But I am stuck for a multiple
>clients scenario. The issue is as follows: Since publishing of data is
>not from the web client but from tcp client , so LWS SERVER WRITABLE
>could not be used to publish data. Hence I have written my own method
>in the websocket server to publish data using LWS_WRITE  for each 
>connection based on unique wsi pointer. But the problem that arises is
>whenever a new client comes in, I get a new wsi pointer and soon after
>LWS_CONNECTION _ESTABLISHED , the new client starts getting data
>without even subscribing for a topic and the older one stops getting
>data. My question is: how can I allow publishing of data only after
>LWS_RECEIVE(after subscription), Can there be any validation that can
>be done between LWS_CONNECTION_ESTABLISHED  and LWS_RECEIVE? Other
>design solutions are also welcome.

I don't really understand this 'tcp client' or 'web client' idea, but there's no reason there should be any confusion between clients at lws.

If you look at how even dumb-increment protocol works, he keeps his clients straight without any problems.  Take a look at how dumd-increment or lws-mirror samples protocol use the per-wsi 'user' pointer.

-Andy

>Please reply. Awaiting response.
>
>Thanks and regards,
>
>Suman
>
>Larsen & Toubro Limited
>
>www.larsentoubro.com
>
>This Email may contain confidential or privileged information for the
>intended recipient (s). If you are not the intended recipient, please
>do not use or disseminate the information, notify the sender and delete
>it from your system.
>
>
>------------------------------------------------------------------------
>
>_______________________________________________
>Libwebsockets mailing list
>Libwebsockets at ml.libwebsockets.org
>http://libwebsockets.org/mailman/listinfo/libwebsockets




More information about the Libwebsockets mailing list