[Libwebsockets] Trouble getting off the ground with minimal examples

Mike J. Bell ckimyt at gmail.com
Fri Aug 20 16:39:48 CEST 2021

Awesome Andy, thanks very much for the pointers and explanation!  I'm going
to work on adapting the binance example to fit my model.


On Fri, Aug 20, 2021 at 10:35 AM Andy Green <andy at warmcat.com> wrote:

> On 8/20/21 2:11 PM, Mike J. Bell wrote:
> > Newbie question.  I'm trying to demonstrate something like the following:
> >
> > LWS-ws-client  <->  LWS-ws-raw-proxy  <->  netcat server
> >
> > I tried out minimal examples to accomplish this.  The LWS-ws-client I
> > used was minimal-ws-client-rx, the LWS-ws-raw-proxy was
> > minimal-ws-raw-proxy, and netcat is netcat of course.  This worked
> > "downstream" when I typed things in at the netcat window, they were
> I'm not sure "trouble getting off the ground" is really your situation,
> it's working in one direction already.
> > transmitted down through the raw proxy to the ws client listener.  (I
> > had to modify the protocol name but once I did that it worked fine).
> >
> > But what I want to do is ALSO schedule (on a regular basis is fine)
> > messages to be sent from the ws-client "upstream" through the raw proxy
> > so that netcat prints them out.
> ws-client-binance shows how to get a periodic callback from the event
> loop, at 1Hz in that example, but it can go much faster.
> https://libwebsockets.org/git/libwebsockets/tree/minimal-examples/ws-client/minimal-ws-client-binance/main.c#n33
> https://libwebsockets.org/git/libwebsockets/tree/minimal-examples/ws-client/minimal-ws-client-binance/main.c#n291-292
> https://libwebsockets.org/git/libwebsockets/tree/minimal-examples/ws-client/minimal-ws-client-binance/main.c#n172-183
> https://libwebsockets.org/git/libwebsockets/tree/minimal-examples/ws-client/minimal-ws-client-binance/main.c#n299
> In the callback, you would call lws_callback_on_writable(wsi); and get a
> WRITEABLE cb as soon as possible to do your write.  This "loop" is
> regulated by the interval for the scheduler, but it is also regulated by
> how fast the peer can accept your data.
> Notice that we cancel the scheduled callback when the wsi is closing,
> since we only start it going once we're established, it should be safe
> against referencing a dead wsi.
> > My question is, can someone point me to a minimal-ws-client example that
> I think you have to accept if what you describe should itself be the
> topic of a "minimal example", someone is going to have to make a lot
> more than 100 of them that exist so far.  That'd be OK, but there are
> only a couple of those that were contributed.
> > both sends messages AND receives them over ws, so I can connect it to
> > the raw proxy?  Or, perhaps, suggest a jumping off point for merging two
> > examples to accomplish what I want?
> This is the better approach.
> -Andy

Mike J. Bell on gmail
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://libwebsockets.org/pipermail/libwebsockets/attachments/20210820/7a2127fb/attachment.htm>

More information about the Libwebsockets mailing list