This commit is contained in:
Erik Frojdh
2019-06-05 17:30:21 +02:00
parent 3d6404952a
commit 03f8b389ad
5 changed files with 1347 additions and 2 deletions

33
tests/src/testserver.cpp Normal file
View File

@ -0,0 +1,33 @@
#include "ServerSocket.h"
#include "clara.hpp"
#include <iostream>
#include "container_utils.h"
int main(int argc, char **argv) {
std::cout << "Test server\n";
int port = 2345;
auto cli = clara::Opt(port, "port")["-p"]["--port"]("Port to send to");
auto result = cli.parse(clara::Args(argc, argv));
if (!result) {
std::cerr << "Error in command line: " << result.errorMessage()
<< std::endl;
exit(1);
}
std::cout << "Listening to port: " << port << "\n";
auto server = sls::ServerSocket(port);
auto data = sls::make_unique<char[]>(5000);
while (true) {
try {
auto socket = server.accept();
auto val = socket.receive<long>();
std::cout << "Value: " << val << "\n";
std::cout << "Read: " << socket.receiveData(data.get(), 5000) << " bytes";
} catch (const sls::RuntimeError &e) {
}
}
}