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

Andy Green andy at warmcat.com
Wed Apr 17 13:56:49 CEST 2019



On 17/04/2019 19:42, Stefano Mora wrote:
> Because I don't see a debug print on the wsCallback() fn on my code:
> 
> 	case LWS_CALLBACK_ESTABLISHED:
> 		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.

-Andy


More information about the Libwebsockets mailing list