[DEV] try to build back test server

This commit is contained in:
Edouard DUPIN 2016-08-09 21:17:44 +02:00
parent e9a67be7ae
commit 02790bef18

View File

@ -8,6 +8,7 @@
#include <enet/Tcp.h> #include <enet/Tcp.h>
#include <enet/Http.h> #include <enet/Http.h>
#include <etk/etk.h> #include <etk/etk.h>
#include <enet/TcpServer.h>
#include <etk/stdTools.h> #include <etk/stdTools.h>
@ -27,22 +28,24 @@ int main(int _argc, const char *_argv[]) {
TEST_INFO("== Test TCP server =="); TEST_INFO("== Test TCP server ==");
TEST_INFO("=================================="); TEST_INFO("==================================");
#ifndef __TARGET_OS__Windows #ifndef __TARGET_OS__Windows
// server mode ... //Wait on TCP connection:
enet::Tcp connection; enet::TcpServer interface;
connection.setHostNane("127.0.0.1"); // Configure server interface:
connection.setPort(31235); interface.setHostNane("127.0.0.1");
connection.setServer(true); interface.setPort(31235);
TEST_INFO("SERVER connect ..."); // Start listening ...
if (connection.link() == false) { interface.link();
TEST_ERROR("can not link to the socket..."); // Wait a new connection ..
return -1; enet::Tcp tcpConnection = std::move(interface.waitNext());
} // Free Connected port
interface.unlink();
int32_t iii = 0; int32_t iii = 0;
while (connection.getConnectionStatus() == enet::Tcp::statusLink) { while (tcpConnection.isAlive() == true) {
int32_t len = connection.write("plop" + etk::to_string(iii)); int32_t len = tcpConnection.write("plop" + etk::to_string(iii));
TEST_INFO("write len=" << len); TEST_INFO("write len=" << len);
char data[1024]; char data[1024];
len = connection.read(data, 1024); len = tcpConnection.read(data, 1024);
if (len > 0) { if (len > 0) {
TEST_INFO("read len=" << len << " data='" << data << "'"); TEST_INFO("read len=" << len << " data='" << data << "'");
} }
@ -50,12 +53,12 @@ int main(int _argc, const char *_argv[]) {
} }
if (iii>=1000000) { if (iii>=1000000) {
TEST_INFO("auto disconnected"); TEST_INFO("auto disconnected");
} else if (connection.getConnectionStatus() != enet::Tcp::statusLink) { } else if (tcpConnection.isAlive() != true) {
TEST_INFO("server disconnected"); TEST_INFO("server disconnected");
} else { } else {
TEST_INFO("ERROR disconnected"); TEST_INFO("ERROR disconnected");
} }
if (connection.unlink() == false) { if (tcpConnection.unlink() == false) {
TEST_ERROR("can not unlink to the socket..."); TEST_ERROR("can not unlink to the socket...");
return -1; return -1;
} }