Pārlūkot izejas kodu

调整websocket初始化到connect

zzj 5 gadi atpakaļ
vecāks
revīzija
20dc32061a
1 mainītis faili ar 21 papildinājumiem un 17 dzēšanām
  1. 21 17
      websocket/wsClient.cpp

+ 21 - 17
websocket/wsClient.cpp

@@ -45,23 +45,6 @@ namespace YA
 		//MsgFuncList.insert( std::make_pair( "beatheart", &web_connect::_beatheart_callback ) );
 
 		__MsgFuncList.insert(std::make_pair("beatheart",&beatheart));
-
-		__wsclient.set_reconnect_attempts( 0 );
-		using std::placeholders::_1;
-		using std::placeholders::_2;
-		using std::placeholders::_3;
-		using std::placeholders::_4;
-		sio::socket::ptr sock = __wsclient.socket();
-		__recv_ping_time = 0;
-		__connet_time = 0;
-		__wsclient.set_open_listener( std::bind( &wsClient::_on_connected, this ) );
-		__wsclient.set_close_listener( std::bind( &wsClient::_on_close, this, std::placeholders::_1 ) );
-		__wsclient.set_reconnect_listener( std::bind( &wsClient::_on_reconnect, this, std::placeholders::_1, std::placeholders::_2 ) );
-		__wsclient.set_fail_listener( std::bind( &wsClient::_on_fail, this ) );
-		__wsclient.set_socket_open_listener( std::bind( &wsClient::_on_socket_opened, this ) );
-
-		sock->on( JSON_CMD_VALUE_CALL, sio::socket::event_listener_aux( std::bind( &wsClient::_OnCallMessage, this, _1, _2, _3, _4 ) ) );
-		sock->on( "code", sio::socket::event_listener_aux( std::bind( &wsClient::_OnLoginResponse, this, _1, _2, _3, _4 ) ) );
 	}
 
 	std::string wsClient::get_uri()
@@ -77,6 +60,27 @@ namespace YA
 			return -1;
 		}
 
+		{
+			__wsclient.set_reconnect_attempts( 0 );
+
+
+			using std::placeholders::_1;
+			using std::placeholders::_2;
+			using std::placeholders::_3;
+			using std::placeholders::_4;
+			sio::socket::ptr sock = __wsclient.socket();
+			__recv_ping_time = 0;
+			__connet_time = 0;
+			__wsclient.set_open_listener( std::bind( &wsClient::_on_connected, this ) );
+			__wsclient.set_close_listener( std::bind( &wsClient::_on_close, this, std::placeholders::_1 ) );
+			__wsclient.set_reconnect_listener( std::bind( &wsClient::_on_reconnect, this, std::placeholders::_1, std::placeholders::_2 ) );
+			__wsclient.set_fail_listener( std::bind( &wsClient::_on_fail, this ) );
+			__wsclient.set_socket_open_listener( std::bind( &wsClient::_on_socket_opened, this ) );
+
+			sock->on( JSON_CMD_VALUE_CALL, sio::socket::event_listener_aux( std::bind( &wsClient::_OnCallMessage, this, _1, _2, _3, _4 ) ) );
+			sock->on( "code", sio::socket::event_listener_aux( std::bind( &wsClient::_OnLoginResponse, this, _1, _2, _3, _4 ) ) );
+		}
+
 		__wsclient.connect( __uri );
 
 		std::cv_status status = std::cv_status::timeout;