Choose hostname and port (for server and client part)

This commit is contained in:
2025-04-30 15:14:10 +03:00
parent cc1bb79633
commit 3b84aa7740
6 changed files with 88 additions and 45 deletions

View File

@@ -1,9 +1,34 @@
#include "server.hpp"
int main(int argc, char **argv) {
Server server;
server.start();
int opt;
std::string host = "localhost";
short unsigned port = 1024u;
while ((opt = getopt(argc, argv, "h:p:")) != -1) {
switch (opt) {
case 'h':
host = optarg;
break;
case 'p':
port = static_cast<unsigned short>(atoi(optarg));
break;
default:
break;
}
}
try {
Server server;
server.start(host, port);
} catch (const std::runtime_error& e){
std::cerr << "Client application error: " << e.what() << std::endl;
return 1;
} catch (...){
std::cerr << "Unexpected error in client application" << std::endl;
return 2;
}
std::cout << "Server application finished" << std::endl;
return 0;
}