[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/Http.h>
#include <etk/etk.h>
#include <enet/TcpServer.h>
#include <etk/stdTools.h>
@ -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;
}