[Libwebsockets] question on websockets protocol name - required?

"Andy Green (林安廸)" andy at warmcat.com
Sat Jan 11 05:52:42 CET 2014


On 08/01/14 06:08, the mail apparently from Michael Haberler included:
> to answer my own question:
>
> Am 06.01.2014 um 22:19 schrieb Michael Haberler
> <andy.green at linaro.org>:
>
>> Hi!
>>
>> so far - looking at examples and being a websocket noob - I was
>> under the impression one had to have a protocols struct with a
>> websocket protocol name, requiring the client to send a
>> "Sec-WebSocket-Protocol: <protocolname>" header
>>
>> now I found this, which just gets away with a single http-only
>> protocol entry:
>> https://github.com/otcshare/automotive-message-broker/blob/master/plugins/websocketsourceplugin/websocketsource.cpp
>>
>>
>>this would make it simpler for some clients which dont support a 
protocol name out of the box, like 
https://pypi.python.org/pypi/websocket-client/ *)
>>
>> question - assume I used this:
>>
>> can I still serve http and websockets from a single callback?
>
> yes - sessions without a Sec-WebSocket-Protocol: header will be
> funneled through the protocol 0 handler (http)

Right... the callbacks for the various actions are all mutually 
exclusive, so for example one callback can handle both the client and 
server sides of a protocol.

The only thing special about protocol[0] is HTTP and extpoll stuff 
specifically targets protocol[0], it doesn't stop you using it as a real 
protocol.  But for the test code, it's easier to understand what's 
happening to separate the callbacks.

> using a protocol name on the client side will abort the session ('Req
> protocol <protocolname> not supported')
>
>> or would that force the scheme to serve only websockets?
>
> no

Right the HTTP serving thing can support anything from HTTP, it's not 
restricted to only websocket upgrade activities.

-Andy

>>
>>
>> thanks in advance,
>>
>> Michael
>>
>> *) it still does, just needs header=["Sec-WebSocket-Protocol:
>> <protocolname>"] in the websocket.WebSocketApp() instantiation
>> _______________________________________________ Libwebsockets
>> mailing list Libwebsockets at ml.libwebsockets.org
>> http://ml.libwebsockets.org/mailman/listinfo/libwebsockets
>
> _______________________________________________ Libwebsockets mailing
> list Libwebsockets at ml.libwebsockets.org
> http://ml.libwebsockets.org/mailman/listinfo/libwebsockets
>




More information about the Libwebsockets mailing list