Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Zaphoyd websocketpp and wss (TLS) Client Example

I have need for fast, secure and portable websockts so I have been digging around the internet and I came across WebSocket++ by Zaphoyd Studios .

I have zero c++ experience (I am a proficient programmer though) but it seems to tick every box I require and I quickly adapted the echo_server and telemetry_client examples up at github and put together a proof of concept.

Setting my hand to the wss server example (echo_server_tls) I quickly compiled and used a simple test client to verify it was working.

Unfortunately, there is where my inexperience fails me, I was naively hoping that changing the url to wss and including the tls enabled client header (asio_client.hpp not asio_no_tls_client.hpp) would set me off in the right direction!

It does not, instead it gives the error;-

[2014-05-29 01:17:58] [application] Get Connection Error: endpoint not secure

So... my question;-

Does anyone have a "echo_client_tls" example as it were to get me headed in the correct direction, I very much doubt that I am the first to do this (perhaps just the most inexperienced with c++ though).

I am sure I can take it from there (I will even submit it back to git as it would probably be useful for other noobs such as my self).

P.S. Kudos to the authors if they ever read this, it seems a very complete implementation!

like image 573
MineForeman Avatar asked May 29 '14 01:05

MineForeman


1 Answers

On top of including the tls enabled client header, the client would need to provide a handler for tls_init. You can modify one of the existing client examples to support tls by adding the following handler.

_client.set_tls_init_handler([this](websocketpp::connection_hdl){
    return websocketpp::lib::make_shared<boost::asio::ssl::context>(boost::asio::ssl::context::tlsv1);
});
like image 85
Mark Avatar answered Nov 02 '22 00:11

Mark