diff --git a/server/robotserver/CMakeLists.txt b/server/robotserver/CMakeLists.txt index 033e292..c847632 100644 --- a/server/robotserver/CMakeLists.txt +++ b/server/robotserver/CMakeLists.txt @@ -10,7 +10,7 @@ endif() set(CMAKE_BUILD_TYPE "Debug") set(CMAKE_CXX_FLAGS_RELEASE "-std=gnu++11 -fsanitize=address -fno-omit-frame-pointer") -set(CMAKE_CXX_FLAGS_DEBUG "-Wall -g -std=gnu++11 -DGAME_ID=${GAME_ID}") +set(CMAKE_CXX_FLAGS_DEBUG "-Wall -g -std=gnu++11 -DGAME_ID=${GAME_ID} -DTCP_CLIENT2=1") include_directories( AFTER diff --git a/server/robotserver/app.h b/server/robotserver/app.h index af934f5..643cf0d 100644 --- a/server/robotserver/app.h +++ b/server/robotserver/app.h @@ -60,8 +60,8 @@ public: int instance_id = 0; bool is_test_mode = false; int test_param = 0; - std::string wsp_host; - int wsp_port = 0; + std::string wsp_host = "192.168.100.21"; + int wsp_port = 7102; std::set flags; private: diff --git a/server/robotserver/virtualclient.cc b/server/robotserver/virtualclient.cc index 04e81a7..9dc2ef6 100644 --- a/server/robotserver/virtualclient.cc +++ b/server/robotserver/virtualclient.cc @@ -3,6 +3,7 @@ #include #include +#include #include "virtualclient.h" #include "app.h" @@ -16,7 +17,11 @@ void VirtualClient::Init() recv_bufflen_ = 0; recv_buff_ = (char*) malloc(PACK_MAX * 2); +#if TCP_CLIENT2 + tcp_client_ = new a8::TcpClient2(); +#else tcp_client_ = new a8::TcpClient(); +#endif tcp_client_->remote_address = remote_ip; tcp_client_->remote_port = remote_port; tcp_client_->on_error = std::bind(&VirtualClient::on_error, this, std::placeholders::_1, std::placeholders::_2); @@ -51,12 +56,20 @@ void VirtualClient::SendMove() } +#if TCP_CLIENT2 +void VirtualClient::on_error(a8::TcpClient2* sender, int errorId) +#else void VirtualClient::on_error(a8::TcpClient* sender, int errorId) +#endif { a8::UdpLog::Instance()->Error("VirtualClient errorid=%d", {errorId}); } +#if TCP_CLIENT2 +void VirtualClient::on_connect(a8::TcpClient2* sender) +#else void VirtualClient::on_connect(a8::TcpClient* sender) +#endif { recv_bufflen_ = 0; a8::UdpLog::Instance()->Info("target server connected", {}); @@ -66,7 +79,11 @@ void VirtualClient::on_connect(a8::TcpClient* sender) ); } +#if TCP_CLIENT2 +void VirtualClient::on_disconnect(a8::TcpClient2* sender) +#else void VirtualClient::on_disconnect(a8::TcpClient* sender) +#endif { recv_bufflen_ = 0; a8::UdpLog::Instance()->Info("target server %d disconnected after 10s later reconnect", {instance_id}); @@ -76,7 +93,11 @@ void VirtualClient::on_disconnect(a8::TcpClient* sender) ); } +#if TCP_CLIENT2 +void VirtualClient::on_socketread(a8::TcpClient2* sender, char* buf, unsigned int len) +#else void VirtualClient::on_socketread(a8::TcpClient* sender, char* buf, unsigned int len) +#endif { if (recv_bufflen_ + len > 2 * PACK_MAX) { recv_bufflen_ = 0; @@ -118,3 +139,4 @@ void VirtualClient::on_socketread(a8::TcpClient* sender, char* buf, unsigned int } recv_bufflen_ -= offset; } + diff --git a/server/robotserver/virtualclient.h b/server/robotserver/virtualclient.h index 1567e46..ed7f95c 100644 --- a/server/robotserver/virtualclient.h +++ b/server/robotserver/virtualclient.h @@ -3,6 +3,7 @@ namespace a8 { class TcpClient; + class TcpClient2; } enum VirtualClientState_e @@ -33,15 +34,26 @@ class VirtualClient void SendMove(); private: +#if TCP_CLIENT2 + void on_error(a8::TcpClient2* sender, int errorId); + void on_connect(a8::TcpClient2* sender); + void on_disconnect(a8::TcpClient2* sender); + void on_socketread(a8::TcpClient2* sender, char* buf, unsigned int len); +#else void on_error(a8::TcpClient* sender, int errorId); void on_connect(a8::TcpClient* sender); void on_disconnect(a8::TcpClient* sender); void on_socketread(a8::TcpClient* sender, char* buf, unsigned int len); +#endif private: VirtualClientState_e state_ = VCS_Init; char *recv_buff_ = nullptr; unsigned int recv_bufflen_ = 0; +#if TCP_CLIENT2 + a8::TcpClient2* tcp_client_ = nullptr; +#else a8::TcpClient* tcp_client_ = nullptr; +#endif }; diff --git a/third_party/a8engine b/third_party/a8engine index 9c2a352..f9222e3 160000 --- a/third_party/a8engine +++ b/third_party/a8engine @@ -1 +1 @@ -Subproject commit 9c2a3520f5459f6260ac4b9b34958ef4c8776a80 +Subproject commit f9222e376f8a678a252932c4a3fb93860d7625f2 diff --git a/third_party/framework b/third_party/framework index 7af5d3b..7f6c831 160000 --- a/third_party/framework +++ b/third_party/framework @@ -1 +1 @@ -Subproject commit 7af5d3b84aeaa84a2979c24db9db5ed5a43cea2d +Subproject commit 7f6c831d8dbef97267f3a87053249d7beb0bf615