[Libwebsockets] question about multi-protocols in libwebsockets

Felix Zhang guojunzhang1981 at gmail.com
Thu Jul 16 20:19:32 CEST 2020


Andy,

Thank you so much.
that's pretty clear to me now.

Sincerely,
Felix

On Wed, Jul 15, 2020 at 10:57 PM Andy Green <andy at warmcat.com> wrote:

>
>
> On 7/16/20 6:24 AM, Felix Zhang wrote:
> > Hi Andy,
> >
> > Hope you are doing well.
>
> I wish...
>
> > I have one question about how to support multiple subprotocol in on a
> > websocket connection.
> > for example,
> > client sends "Sec-WebSocket-Protocol: protocol-a, protocol-b, protocol-c"
> > and server selects only "protocol-a" and "protocol-c" and the response
> > like" Sec-WebSocket-Protocol: protocol-a, protocol-c ".
>
> That's not quite how it works, the server must pick one that it likes
> best and let the client know what it picked.  Since it will be running
> only one negotiated protocol over an individual socket.
>
> The client then typically binds to the local lws_protocols struct with
> the selected name, allocates user data according to that etc.
>
> > Is this a common case? and do we support this case today?
> > Thanks in advance.
>
> Client offering multiple protocols is a normal, standardized case.
>
> The lws client info struct member can take a comma-separated list:
>
>
> https://libwebsockets.org/git/libwebsockets/tree/include/libwebsockets/lws-client.h#n84-85
>
> On the server side, it goes through what the client sent from left to
> right, and picks the first one it has support for:
>
>
> https://libwebsockets.org/git/libwebsockets/tree/lib/roles/ws/server-ws.c#n496-536
>
> It's not specified in RFC6455 but it's assumed the client placed them in
> order of highest preference first.
>
> -Andy
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://libwebsockets.org/pipermail/libwebsockets/attachments/20200716/ef92946b/attachment.htm>


More information about the Libwebsockets mailing list