[Libwebsockets] R: R: R: R: R: Unable to connect to the server with Android

Stefano Mora stefano.mora at newdep.com
Wed Apr 17 14:48:23 CEST 2019

I forced the sec-websocket-protocol value and it worked!!


-----Messaggio originale-----
Da: Andy Green <andy at warmcat.com> 
Inviato: mercoledì 17 aprile 2019 13:57
A: Stefano Mora <stefano.mora at newdep.com>
Cc: libwebsockets at ml.libwebsockets.org
Oggetto: Re: R: R: R: R: [Libwebsockets] Unable to connect to the server with Android

On 17/04/2019 19:42, Stefano Mora wrote:
> Because I don't see a debug print on the wsCallback() fn on my code:
> 		lwsl_timestamp( LLL_USER,  timestamp, TIMESTAMP_SIZE);
> 		lwsl_user("%s[protocol_lws.c][wsCallback] LWS_CALLBACK_ESTABLISHED [run:%d][nCli:%d]\n", timestamp, engineData.bIsRunning, engineData.nNumeroClients);
> 		lwsl_user("%s[protocol_lws.c] pss=%p wsi=%p\n", timestamp, pss, 
> wsi);

Then probably the problem is related to protocol selection... your client doesn't send sec-websocket-protocol: so lws can bind to the desired protocol by name.

By default under those conditions lws binds the connection to the first protocol, which is often the http-only / dummy protocol, ie, not what you want.

You can control which protocol gets matched to these clients who don't specify a protocol by attaching a pvo (per-vhost option) to it with the name "default" (the value is not important).

You can do that in code like this:

static const struct lws_protocol_vhost_options pvo_def = {
	NULL, NULL, "default", ""
}, pvo = {
	NULL, &pvo_def, "name-of-your-protocol", ""

then when creating the vhost (or context if you only have the default vhost)

	info.pvo = &pvo;

That will then bind the protocol "name-of-your-protocol" to these clients who don't specify a subprotocol name on that vhost.


More information about the Libwebsockets mailing list