how does websocketpp handle connections when set_tls_init_handler is not set?

562 Views Asked by At

I see that I have to define an on_tls_init and have the set_tls_init_handler to point to this on_tls_init for secure connections. What happens when set_tls_init_handler is not set? Does webscoketpp go head with the connection over ws:// instead of wss:// or is the connection dropped?

1

There are 1 best solutions below

0
zaphoyd On

WebSocket++'s transport security behavior is based on which config your endpoint uses. If your endpoint is configured to be secure, i.e. using a config, like websocketpp::config::asio whose transport socket type performs TLS encryption then not defining a tls init handler (or not returning a valid TLS context from it) will result in connections failing with an invalid_tls_context error.

If you want plain/unencrypted/"ws://" connections you should use an endpoing config that does not perform TLS encryption (for example websocketpp::config::asio_no_tls). An endpoint compiled with that config will ignore the tls handler.