@@ -49,7 +49,9 @@ namespace sio
4949 m_client.set_close_handler (lib::bind (&client_impl::on_close,this ,_1));
5050 m_client.set_fail_handler (lib::bind (&client_impl::on_fail,this ,_1));
5151 m_client.set_message_handler (lib::bind (&client_impl::on_message,this ,_1,_2));
52-
52+ #if SIO_TLS
53+ m_client.set_tls_init_handler (lib::bind (&client_impl::on_tls_init,this ,_1));
54+ #endif
5355 m_packet_mgr.set_decode_callback (lib::bind (&client_impl::on_decode,this ,_1));
5456
5557 m_packet_mgr.set_encode_callback (lib::bind (&client_impl::on_encode,this ,_1,_2));
@@ -198,13 +200,17 @@ namespace sio
198200 do {
199201 websocketpp::uri uo (uri);
200202 ostringstream ss;
201-
203+ #if SIO_TLS
204+ ss<<" wss://" ;
205+ #else
206+ ss<<" ws://" ;
207+ #endif
202208 if (m_sid.size ()==0 ) {
203- ss<<" ws:// " << uo.get_host ()<<" :" <<uo.get_port ()<<" /socket.io/?EIO=4&transport=websocket&t=" <<time (NULL )<<queryString;
209+ ss<<uo.get_host ()<<" :" <<uo.get_port ()<<" /socket.io/?EIO=4&transport=websocket&t=" <<time (NULL )<<queryString;
204210 }
205211 else
206212 {
207- ss<<" ws:// " << uo.get_host ()<<" :" <<uo.get_port ()<<" /socket.io/?EIO=4&transport=websocket&sid=" <<m_sid<<" &t=" <<time (NULL )<<queryString;
213+ ss<<uo.get_host ()<<" :" <<uo.get_port ()<<" /socket.io/?EIO=4&transport=websocket&sid=" <<m_sid<<" &t=" <<time (NULL )<<queryString;
208214 }
209215 lib::error_code ec;
210216 client_type::connection_ptr con = m_client.get_connection (ss.str (), ec);
@@ -549,4 +555,21 @@ namespace sio
549555 m_sid.clear ();
550556 m_packet_mgr.reset ();
551557 }
558+
559+ #if SIO_TLS
560+ client_impl::context_ptr client_impl::on_tls_init (connection_hdl conn)
561+ {
562+ context_ptr ctx = context_ptr (new boost::asio::ssl::context (boost::asio::ssl::context::tlsv1));
563+ boost::system::error_code ec;
564+ ctx->set_options (boost::asio::ssl::context::default_workarounds |
565+ boost::asio::ssl::context::no_sslv2 |
566+ boost::asio::ssl::context::single_dh_use,ec);
567+ if (ec)
568+ {
569+ cerr<<" Init tls failed,reason:" << ec.message ()<<endl;
570+ }
571+
572+ return ctx;
573+ }
574+ #endif
552575}
0 commit comments