2022-09-20 13:37:06 +00:00
|
|
|
#include <ap/ap.hpp>
|
|
|
|
#include <server/tcp_server.hpp>
|
2022-09-08 07:31:37 +00:00
|
|
|
#include <iostream>
|
|
|
|
|
2022-09-20 13:37:06 +00:00
|
|
|
void server(int port)
|
2022-09-08 07:31:37 +00:00
|
|
|
{
|
2022-09-20 13:37:06 +00:00
|
|
|
using namespace azh;
|
|
|
|
|
|
|
|
TCPServer server(IPV::V4, port);
|
|
|
|
server.run();
|
2022-09-08 07:31:37 +00:00
|
|
|
}
|
|
|
|
|
2022-09-20 13:37:06 +00:00
|
|
|
int main(int argc, char *argv[])
|
2022-09-08 07:31:37 +00:00
|
|
|
{
|
2022-09-20 13:37:06 +00:00
|
|
|
ap::Hub hub( { { "port", 'p', ap::REQUIRED }, { "host", 'h', ap::OPTIONAL }, { "server", 's', ap::NO }, { "client", 'c', ap::NO } });
|
|
|
|
hub.readArguments(argc, argv);
|
2022-09-08 07:31:37 +00:00
|
|
|
|
2022-09-20 13:37:06 +00:00
|
|
|
auto optionPort = hub.getOption('p');
|
|
|
|
if (!optionPort.isSet())
|
2022-09-08 07:31:37 +00:00
|
|
|
{
|
2022-09-20 13:37:06 +00:00
|
|
|
std::cerr << "Порт не был установлен!" << std::endl;
|
|
|
|
exit(EXIT_FAILURE);
|
2022-09-08 07:31:37 +00:00
|
|
|
}
|
|
|
|
|
2022-09-20 13:37:06 +00:00
|
|
|
int port = std::stoi(optionPort.getValues()[0]);
|
2022-09-08 07:31:37 +00:00
|
|
|
|
2022-09-20 13:37:06 +00:00
|
|
|
auto optionClient = hub.getOption('c');
|
|
|
|
auto optionServer = hub.getOption('s');
|
2022-09-08 07:31:37 +00:00
|
|
|
|
2022-09-20 13:37:06 +00:00
|
|
|
if (optionClient.isSet())
|
2022-09-08 07:31:37 +00:00
|
|
|
{
|
2022-09-20 13:37:06 +00:00
|
|
|
auto optionHost = hub.getOption('h');
|
|
|
|
if (!optionHost.isSet())
|
2022-09-08 07:31:37 +00:00
|
|
|
{
|
2022-09-20 13:37:06 +00:00
|
|
|
std::cerr << "Адрес не был установлен!" << std::endl;
|
|
|
|
exit(EXIT_FAILURE);
|
2022-09-08 07:31:37 +00:00
|
|
|
}
|
|
|
|
|
2022-09-20 13:37:06 +00:00
|
|
|
auto host = optionHost.getValues()[0];
|
2022-09-08 07:31:37 +00:00
|
|
|
|
2022-09-20 13:37:06 +00:00
|
|
|
// client(port, host);
|
2022-09-08 07:31:37 +00:00
|
|
|
}
|
2022-09-20 13:37:06 +00:00
|
|
|
else if (optionServer.isSet())
|
|
|
|
server(port);
|
|
|
|
else
|
2022-09-08 07:31:37 +00:00
|
|
|
{
|
2022-09-20 13:37:06 +00:00
|
|
|
std::cerr << "Необходимо установить режим запуска:" << std::endl << "\t-c\t--client\tЗапуск в режиме клиента" << std::endl
|
|
|
|
<< "\t-s\t--server\tЗапуск в режиме сервера" << std::endl << "\t-h\t--host\t\tУказать IP-адрес сервера" << std::endl
|
|
|
|
<< "\t-p\t--port\t\tУказать порт" << std::endl;
|
|
|
|
exit(EXIT_FAILURE);
|
2022-09-08 07:31:37 +00:00
|
|
|
}
|
|
|
|
|
2022-09-20 13:37:06 +00:00
|
|
|
return 0;
|
2022-09-08 07:31:37 +00:00
|
|
|
}
|