From 02790bef185f307b1ee76012558c3a0327c05980 Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Tue, 9 Aug 2016 21:17:44 +0200 Subject: [PATCH] [DEV] try to build back test server --- test/main-server.cpp | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/test/main-server.cpp b/test/main-server.cpp index 8e68268..2068314 100644 --- a/test/main-server.cpp +++ b/test/main-server.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include @@ -27,22 +28,24 @@ int main(int _argc, const char *_argv[]) { TEST_INFO("== Test TCP server =="); TEST_INFO("=================================="); #ifndef __TARGET_OS__Windows - // server mode ... - enet::Tcp connection; - connection.setHostNane("127.0.0.1"); - connection.setPort(31235); - connection.setServer(true); - TEST_INFO("SERVER connect ..."); - if (connection.link() == false) { - TEST_ERROR("can not link to the socket..."); - return -1; - } + //Wait on TCP connection: + enet::TcpServer interface; + // Configure server interface: + interface.setHostNane("127.0.0.1"); + interface.setPort(31235); + // Start listening ... + interface.link(); + // Wait a new connection .. + enet::Tcp tcpConnection = std::move(interface.waitNext()); + // Free Connected port + interface.unlink(); + int32_t iii = 0; - while (connection.getConnectionStatus() == enet::Tcp::statusLink) { - int32_t len = connection.write("plop" + etk::to_string(iii)); + while (tcpConnection.isAlive() == true) { + int32_t len = tcpConnection.write("plop" + etk::to_string(iii)); TEST_INFO("write len=" << len); char data[1024]; - len = connection.read(data, 1024); + len = tcpConnection.read(data, 1024); if (len > 0) { TEST_INFO("read len=" << len << " data='" << data << "'"); } @@ -50,12 +53,12 @@ int main(int _argc, const char *_argv[]) { } if (iii>=1000000) { TEST_INFO("auto disconnected"); - } else if (connection.getConnectionStatus() != enet::Tcp::statusLink) { + } else if (tcpConnection.isAlive() != true) { TEST_INFO("server disconnected"); } else { TEST_INFO("ERROR disconnected"); } - if (connection.unlink() == false) { + if (tcpConnection.unlink() == false) { TEST_ERROR("can not unlink to the socket..."); return -1; }