[Libwebsockets] Question about protocol-0 callback design in External Polling application

Andy Green andy at warmcat.com
Mon May 11 19:13:48 CEST 2020



On 5/11/20 5:31 PM, John Peter Norair wrote:
> Hello:
> 
> I’m building a websocket<—>unix-socket bridge.  Perhaps one already 
> exists, but I haven’t found it.  I will open source my software if it 
> ends up being worth releasing.

Yes it should work fine.

Lws already supports reverse proxying http and ws over a unix domain 
socket (-DLWS_WITH_HTTP_PROXY=1).  When you visit gitohashi or sai

https://libwebsockets.org/git/libwebsockets

actually that's a separate process than the lws-based webserver you're 
connecting to, proxied over a unix domain socket at the server.

You can implement it using mounts like this example

https://libwebsockets.org/git/libwebsockets/tree/minimal-examples/http-server/minimal-http-server/minimal-http-server.c#n37

Set the .origin to something like "+/var/run/sai:/sai" (the unix socket 
path and then the proxied http base path) and .origin_protocol to 
LWSMPRO_HTTP.

Mountpoint is where the proxy is placed in the url space of the server.

> I’m looking at this page (below).  It seems simple enough.
> https://libwebsockets.org/lws-api-doc-master/html/md_README.coding.html
> 
> What’s less simple is extracting lws_callback_http_dummy() from the lws 
> sources and removing the parts of it that link to sections I’d prefer 
> not to include in my application sources (i.e. I’d prefer to keep them 
> in the lib).

You don't need to do any of that.

> I would appreciate any guidance in minimizing lws_callback_http_dummy(). 

It's an export from lws

https://libwebsockets.org/git/libwebsockets/tree/include/libwebsockets/lws-writeable.h#n189-191

if you need something that's in it, you can just call through to the 
library exported version if nothing else in your protocol wanted to 
handle it, eg

https://libwebsockets.org/git/libwebsockets/tree/minimal-examples/http-server/minimal-http-server-dynamic/minimal-http-server-dynamic.c#n178

-Andy

>   If there’s already a program or example that does this, even better. 
>   My application doesn’t require HTTP functionality beyond what’s shown 
> in the minimal-examples/ws-server/minimal-ws-server example code (this 
> uses lws_callback_http_dummy()).
> 
> Best regards,
> JPN
> 
> _______________________________________________
> Libwebsockets mailing list
> Libwebsockets at ml.libwebsockets.org
> https://libwebsockets.org/mailman/listinfo/libwebsockets
> 


More information about the Libwebsockets mailing list