[Libwebsockets] Howto create a WSS enabled Client in C/C++

Mooki Moo mookimoo73 at gmail.com
Tue May 1 13:49:19 CEST 2018

Hello All.

I have a (DigiCert) enabled WSS Server running that I can successfully
connect to and communicate with via my web site, and I am now looking
to connect a C/C++ client to this but when I execute
lws_client_connect_via_info function I get :

NOTICE: libuv support not compiled in
NOTICE: Creating Vhost 'default' port -1, 3 protocols, IPv6 off
NOTICE: created client ssl context for default

followed by a seg fault. I’ve searched the internet but I have found
nothing that demonstrates how to implement a WSS enabled client so I’m
looking for some assistance in doing this.

As a starter I have been referring to this :


And as I have no need for a Client Certificate I have set my
lws_context_creation_info struct thus:

ctxinfo.port = CONTEXT_PORT_NO_LISTEN ;
ctxinfo.iface = NULL;
ctxinfo.protocols = protocols ;
ctxinfo.extensions = 0 ;
ctxinfo.gid = -1;
ctxinfo.uid = -1;
ctxinfo.ssl_cert_filepath = NULL ;
ctxinfo.ssl_private_key_filepath = NULL ;
ctxinfo.ssl_ca_filepath = rootPath ;

context = lws_create_context(&ctxinfo);

and further I  configured by lws_client_connect_info struct as follows :

const char * serverAddr = “mydomain.ok” ;

client.path = "/" ;
client.port = wssPort ;
client.context = context ;
client.ssl_connection = LCCSCF_USE_SSL ;
client.address = serverAddr ;
client.host = serverAddr ;
client.origin = serverAddr ;
client.ietf_version_or_minus_one = -1 ;
client.protocol = protocols[ProtoList::Data].name ;
client.pwsi = &wsiData ;

But as I said above when I call the
lws_client_connect_via_info(&client) I get the output above followed
by a seg fault. I know I am doing something wrong but I cannot see
what it is so your help would be appreciated.

More information about the Libwebsockets mailing list