45 using websocketpp::lib::placeholders::_1;
46 using websocketpp::lib::placeholders::_2;
47 using websocketpp::lib::bind;
51 typedef websocketpp::lib::shared_ptr<websocketpp::lib::asio::ssl::context>
context_ptr;
54 std::cout <<
"on_message called with hdl: " << hdl.lock().get()
55 <<
" and message: " << msg->get_payload()
59 s->
send(hdl, msg->get_payload(), msg->get_opcode());
61 std::cout <<
"Echo failed because: " 62 <<
"(" << e.
what() <<
")" << std::endl;
69 con->set_body(
"Hello World!");
87 std::cout <<
"on_tls_init called with hdl: " << hdl.lock().get() << std::endl;
88 std::cout <<
"using TLS mode: " << (mode ==
MOZILLA_MODERN ?
"Mozilla Modern" :
"Mozilla Intermediate") << std::endl;
90 context_ptr ctx = websocketpp::lib::make_shared<asio::ssl::context>(asio::ssl::context::sslv23);
95 ctx->set_options(asio::ssl::context::default_workarounds |
96 asio::ssl::context::no_sslv2 |
97 asio::ssl::context::no_sslv3 |
98 asio::ssl::context::no_tlsv1 |
99 asio::ssl::context::single_dh_use);
101 ctx->set_options(asio::ssl::context::default_workarounds |
102 asio::ssl::context::no_sslv2 |
103 asio::ssl::context::no_sslv3 |
104 asio::ssl::context::single_dh_use);
107 ctx->use_certificate_chain_file(
"server.pem");
108 ctx->use_private_key_file(
"server.pem", asio::ssl::context::pem);
114 ctx->use_tmp_dh_file(
"dh.pem");
119 ciphers =
"ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!3DES:!MD5:!PSK";
121 ciphers =
"ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:AES:CAMELLIA:DES-CBC3-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!aECDH:!EDH-DSS-DES-CBC3-SHA:!EDH-RSA-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA";
124 if (SSL_CTX_set_cipher_list(ctx->native_handle() , ciphers.c_str()) != 1) {
125 std::cout <<
"Error setting cipher list" << std::endl;
127 }
catch (std::exception& e) {
128 std::cout <<
"Exception: " << e.what() << std::endl;
138 echo_server.init_asio();
146 echo_server.listen(9002);
websocketpp::config::asio_tls_client::message_type::ptr message_ptr
websocketpp::lib::shared_ptr< websocketpp::lib::asio::ssl::context > context_ptr
std::string get_password()
websocketpp::config::asio::message_type::ptr message_ptr
void on_message(server *s, websocketpp::connection_hdl hdl, message_ptr msg)
void on_http(server *s, websocketpp::connection_hdl hdl)
lib::weak_ptr< void > connection_hdl
A handle to uniquely identify a connection.
connection_ptr get_con_from_hdl(connection_hdl hdl, lib::error_code &ec)
Retrieves a connection_ptr from a connection_hdl (exception free)
context_ptr on_tls_init(tls_mode mode, websocketpp::connection_hdl hdl)
lib::shared_ptr< message > ptr
void start_accept(lib::error_code &ec)
Starts the server's async connection acceptance loop (exception free)
Server endpoint role based on the given config.
void set_http_handler(http_handler h)
websocketpp::server< websocketpp::config::asio_tls > server
NOTES.
connection_type::ptr connection_ptr
Type of a shared pointer to the connections this server will create.
websocketpp::lib::shared_ptr< boost::asio::ssl::context > context_ptr
void set_message_handler(message_handler h)
virtual char const * what() const
void send(connection_hdl hdl, std::string const &payload, frame::opcode::value op, lib::error_code &ec)
Create a message and add it to the outgoing send queue (exception free)