[Libwebsockets] Best approach to combine https polling with perpetual wss connection

Andy Green andy at warmcat.com
Mon Dec 5 22:31:00 CET 2016



On December 6, 2016 4:37:41 AM GMT+08:00, Michael Behrns-Miller <moodboom at gmail.com> wrote:
>Hey Andy, can you suggest how you would approach setting up this pseudo
>loop?
>
>    while !exit
>        if ready-to-poll { start http-get }
>        if have-polled-data { send wss }
>
>The http calls poll data on one server/port, and as data is gathered
>it is sent to another wss server/port.  Do I want one lws_service /

If I understand these are both clients.

>protocol callback that handles both https and wss?  Will this require

The callback reasons are different for http and ws.  So you can do it all in one callback.

But it's easier to see what's going on if you have a separate protocol for the wss part.

>one or two contexts?  I was hoping to get your suggested approach

Always one context.  The context holds some processwide things.

The test client already demonstrates most of the pieces you need (multiple client connections in one context, GET, wss, automatic ratelimited reconnect).

Basically when your GET brings some data, you stash it (in a ringbuffer if a lot of it expected) and ask for a callback when the wss side is writable (if the wss side is disconnected, set a flag and repeat when back up).  In the writable callback for wss side, send and retire a chunk of the data and ask for another writable callback if more data pending.

Play with the test client as-is, then cut-and-paste it as the starting point for your app (it's CC0 license for that purpose), ripping out whatever is not needed.  Git is your friend when doing this, since it works from the start, if you break it while adapting it, you can know which change broke it if you have been carefully committing everything.

-Andy

>before I dive in too far.
>
>Thanks!
>Michael Behrns-Miller
>_______________________________________________
>Libwebsockets mailing list
>Libwebsockets at ml.libwebsockets.org
>http://libwebsockets.org/mailman/listinfo/libwebsockets




More information about the Libwebsockets mailing list