[Libwebsockets] Trying to get protocol callback mount to work

Alex Stagg alex at bitrouter.com
Thu Oct 11 01:25:40 CEST 2018


Hi Andy,

Thank you for responding quickly and addressing my concerns.

I agree that defining the ws subprotocol would be the best approach. However, I am not specifying the protocol, for which there is no subprotocol name defined, and I don't know if I will be able influence a change to it.

As you mentioned, I was able to get access to the URL on the ESTABLISHED callback, and I will use that as a fallback approach for tracking and dispatching a URL-specific callback for each connection.

Best Regards,

 - Alex Stagg


-----Original Message-----
From: Andy Green <andy at warmcat.com> 
Sent: Wednesday, October 10, 2018 2:20 PM
To: libwebsockets at ml.libwebsockets.org; Alex Stagg <alex at bitrouter.com>
Subject: Re: [Libwebsockets] Trying to get protocol callback mount to work



On October 11, 2018 12:01:53 AM GMT+08:00, Alex Stagg <alex at bitrouter.com> wrote:
>I have client and server test programs using libwebsockets to simulate 
>a client-initiated websockets connection without a (websockets 
>sub-)protocol name, and get the server to assign it to one of several 
>protocol callbacks based on the URL.

I guess it's already obvious, but having the client just specify the ws subprotocol is what ws and lws expect you to do, and it will just work for identifying which lws_protocols to bind to.

>When I specify a protocol string in the client connection info that 
>matches the name of protocol 1 on both sides, the connection is 
>assigned to protocol
>1 on both sides, as I would expect. If I specify NULL as the protocol 
>string pointer in the client connection info, then I get the connection 
>assigned to protocol 0 on both sides as normally expected without using 
>URL mounts.

Okay, but mounts are an http thing.  At the time you try to upgrade the http connection to ws, not GET or PUSH, they are not consulted.

>Am I incorrect in understanding that properly configuring URL mounts 
>can get the connection with no protocol from the client side assigned 
>to protocol 1 (at least on the server side)? If so, I have not been 
>able to get this to

Nothing claims that would work on lws side for ws... the mount support for CALLBACK mounts is only for http, as used in the POST example plugin to bind a chunk of URL space to be handled by that plugin.

Not having a subprotocol means there's a 'default' protocol per-vhost that gets mapped at upgrade time (itself defaulting to protocol 0).  If the upgrade has the subprotocol header, then that alone selects the protocol it binds to, by name matching.

>work regardless of how I try to match values in the server's struct 
>lws_http_mount with the client's connection info, and the protocol 
>arrays.
>What info would someone need to help me debug this?

The only bug in this is your client thinks not sending the ws subprotocol name was a good idea and the limitations caused by it being a bad idea should be hacked around in lws.

If you're stuck with that, notice that the parsed http headers are still available at ESTABLISHED.  You can fish out the URL part there and set your own function pointer held in the pss to the correct handler.  Then in your single lws protocol, call through to the sub-handler you selected at ESTABLISHED time.  Or some variation of that.

-Andy

> 
>
>*	Alex Stagg
>
> 



More information about the Libwebsockets mailing list