12 using websocketpp::lib::placeholders::_1;
13 using websocketpp::lib::placeholders::_2;
14 using websocketpp::lib::bind;
17 typedef websocketpp::lib::shared_ptr<boost::asio::ssl::context>
context_ptr;
21 template <
typename Endpo
intType>
25 std::cout <<
"on_message called with hdl: " << hdl.lock().get()
26 <<
" and message: " << msg->get_payload()
30 s->send(hdl, msg->get_payload(), msg->get_opcode());
32 std::cout <<
"Echo failed because: " 33 <<
"(" << e.
what() <<
")" << std::endl;
43 std::cout <<
"on_tls_init called with hdl: " << hdl.lock().get() << std::endl;
44 context_ptr ctx(
new boost::asio::ssl::context(boost::asio::ssl::context::tlsv1));
47 ctx->set_options(boost::asio::ssl::context::default_workarounds |
48 boost::asio::ssl::context::no_sslv2 |
49 boost::asio::ssl::context::no_sslv3 |
50 boost::asio::ssl::context::single_dh_use);
52 ctx->use_certificate_chain_file(
"server.pem");
53 ctx->use_private_key_file(
"server.pem", boost::asio::ssl::context::pem);
54 }
catch (std::exception& e) {
55 std::cout << e.what() << std::endl;
63 boost::asio::io_service ios;
68 endpoint_plain.init_asio(&ios);
70 bind(&on_message<server_plain>,&endpoint_plain,::_1,::_2));
71 endpoint_plain.listen(80);
78 bind(&on_message<server_tls>,&endpoint_tls,::_1,::_2));
websocketpp::config::asio_tls_client::message_type::ptr message_ptr
void on_message(EndpointType *s, websocketpp::connection_hdl hdl, typename EndpointType::message_ptr msg)
websocketpp::lib::shared_ptr< boost::asio::ssl::context > context_ptr
websocketpp::server< websocketpp::config::asio_tls > server_tls
lib::weak_ptr< void > connection_hdl
A handle to uniquely identify a connection.
void init_asio(io_service_ptr ptr, lib::error_code &ec)
initialize asio transport with external io_service (exception free)
void set_tls_init_handler(tls_init_handler h)
Set TLS init handler.
void start_accept(lib::error_code &ec)
Starts the server's async connection acceptance loop (exception free)
context_ptr on_tls_init(websocketpp::connection_hdl hdl)
void listen(lib::asio::ip::tcp::endpoint const &ep, lib::error_code &ec)
Set up endpoint for listening manually (exception free)
websocketpp::lib::shared_ptr< boost::asio::ssl::context > context_ptr
void set_message_handler(message_handler h)
virtual char const * what() const
std::string get_password()
websocketpp::server< websocketpp::config::asio > server_plain