@@ -222,7 +222,7 @@ namespace sio
222222 } else {
223223 ss<<uo.get_host ();
224224 }
225- ss<<" :" <<uo.get_port ()<<" /socket.io/?EIO=3 &transport=websocket" ;
225+ ss<<" :" <<uo.get_port ()<<" /socket.io/?EIO=4 &transport=websocket" ;
226226 if (m_sid.size ()>0 ){
227227 ss<<" &sid=" <<m_sid;
228228 }
@@ -295,12 +295,6 @@ namespace sio
295295 lib::error_code ec;
296296 this ->m_client .send (this ->m_con , *payload, frame::opcode::text, ec);
297297 });
298- if (m_ping_timer)
299- {
300- asio::error_code e_code;
301- m_ping_timer->expires_from_now (milliseconds (m_ping_interval), e_code);
302- m_ping_timer->async_wait (std::bind (&client_impl::ping,this , std::placeholders::_1));
303- }
304298 if (!m_ping_timeout_timer)
305299 {
306300 m_ping_timeout_timer.reset (new asio::steady_timer (m_client.get_io_service ()));
@@ -497,21 +491,21 @@ namespace sio
497491 m_ping_timeout = 60000 ;
498492 }
499493
500- m_ping_timer.reset (new asio::steady_timer (m_client.get_io_service ()));
501- asio::error_code ec;
502- m_ping_timer->expires_from_now (milliseconds (m_ping_interval), ec);
503- if (ec)LOG (" ec:" <<ec.message ()<<endl){};
504- m_ping_timer->async_wait (std::bind (&client_impl::ping,this , std::placeholders::_1));
505- LOG (" On handshake,sid:" <<m_sid<<" ,ping interval:" <<m_ping_interval<<" ,ping timeout" <<m_ping_timeout<<endl);
506494 return ;
507495 }
508496failed:
509497 // just close it.
510498 m_client.get_io_service ().dispatch (std::bind (&client_impl::close_impl, this ,close::status::policy_violation," Handshake error" ));
511499 }
512500
513- void client_impl::on_pong ()
501+ void client_impl::on_ping ()
514502 {
503+ packet p (packet::frame_pong);
504+ m_packet_mgr.encode (p, [&](bool /* isBin*/ ,shared_ptr<const string> payload)
505+ {
506+ this ->m_client .send (this ->m_con , *payload, frame::opcode::text);
507+ });
508+
515509 if (m_ping_timeout_timer)
516510 {
517511 m_ping_timeout_timer->cancel ();
@@ -536,8 +530,8 @@ namespace sio
536530 // FIXME how to deal?
537531 this ->close_impl (close::status::abnormal_close, " End by server" );
538532 break ;
539- case packet::frame_pong :
540- this ->on_pong ();
533+ case packet::frame_ping :
534+ this ->on_ping ();
541535 break ;
542536
543537 default :
@@ -560,11 +554,6 @@ namespace sio
560554 m_ping_timeout_timer->cancel (ec);
561555 m_ping_timeout_timer.reset ();
562556 }
563- if (m_ping_timer)
564- {
565- m_ping_timer->cancel (ec);
566- m_ping_timer.reset ();
567- }
568557 }
569558
570559 void client_impl::reset_states ()
0 commit comments