Network: Print used port on startup and change default to 6742

Also print an error if server can't be started

1337 is already used by razer's rest server
Port idea by @bahorn (6742 = ORGB on a phone numpad)
This commit is contained in:
Térence Clastres 2020-06-20 13:49:59 +02:00 committed by Adam Honse
parent 0286a5dd58
commit 6d585d3eeb
2 changed files with 5 additions and 3 deletions

View file

@ -37,7 +37,7 @@ static void Sleep(unsigned int milliseconds)
NetworkClient::NetworkClient(std::vector<RGBController *>& control) : controllers(control) NetworkClient::NetworkClient(std::vector<RGBController *>& control) : controllers(control)
{ {
strcpy(port_ip, "127.0.0.1"); strcpy(port_ip, "127.0.0.1");
port_num = 1337; port_num = 6742;
server_connected = false; server_connected = false;
server_controller_count = 0; server_controller_count = 0;
} }

View file

@ -37,7 +37,7 @@ static void Sleep(unsigned int milliseconds)
NetworkServer::NetworkServer(std::vector<RGBController *>& control) : controllers(control) NetworkServer::NetworkServer(std::vector<RGBController *>& control) : controllers(control)
{ {
port_num = 1337; port_num = 6742;
server_online = false; server_online = false;
} }
@ -134,6 +134,7 @@ void NetworkServer::StartServer()
server_sock = socket(AF_INET, SOCK_STREAM, 0); server_sock = socket(AF_INET, SOCK_STREAM, 0);
if (server_sock == INVALID_SOCKET) if (server_sock == INVALID_SOCKET)
{ {
printf("Error: network socket could not be created\n");
WSACleanup(); WSACleanup();
return; return;
} }
@ -150,6 +151,7 @@ void NetworkServer::StartServer()
\*-------------------------------------------------*/ \*-------------------------------------------------*/
if (bind(server_sock, (sockaddr*)&myAddress, sizeof(myAddress)) == SOCKET_ERROR) if (bind(server_sock, (sockaddr*)&myAddress, sizeof(myAddress)) == SOCKET_ERROR)
{ {
printf("Error: Could not bind network socket \nIs port %hu already being used?\n", GetPort());
WSACleanup(); WSACleanup();
return; return;
} }
@ -200,7 +202,7 @@ void NetworkServer::ConnectionThreadFunction()
{ {
//This thread handles client connections //This thread handles client connections
printf("Network connection thread started\n"); printf("Network connection thread started on port %hu\n", GetPort());
while(server_online == true) while(server_online == true)
{ {
/*-------------------------------------------------*\ /*-------------------------------------------------*\