@@ -49,7 +49,9 @@ namespace sio
49
49
m_client.set_close_handler (lib::bind (&client_impl::on_close,this ,_1));
50
50
m_client.set_fail_handler (lib::bind (&client_impl::on_fail,this ,_1));
51
51
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
53
55
m_packet_mgr.set_decode_callback (lib::bind (&client_impl::on_decode,this ,_1));
54
56
55
57
m_packet_mgr.set_encode_callback (lib::bind (&client_impl::on_encode,this ,_1,_2));
@@ -198,13 +200,17 @@ namespace sio
198
200
do {
199
201
websocketpp::uri uo (uri);
200
202
ostringstream ss;
201
-
203
+ #if SIO_TLS
204
+ ss<<" wss://" ;
205
+ #else
206
+ ss<<" ws://" ;
207
+ #endif
202
208
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;
204
210
}
205
211
else
206
212
{
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;
208
214
}
209
215
lib::error_code ec;
210
216
client_type::connection_ptr con = m_client.get_connection (ss.str (), ec);
@@ -549,4 +555,21 @@ namespace sio
549
555
m_sid.clear ();
550
556
m_packet_mgr.reset ();
551
557
}
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
552
575
}
0 commit comments