From ef869710e51d4053369bda19cf2e96df8a8c68a6 Mon Sep 17 00:00:00 2001 From: Rockingcool Date: Tue, 12 Mar 2024 09:44:15 -0500 Subject: [PATCH] Replaced recvAll call with recvAllNB --- main.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/main.cpp b/main.cpp index 49db3f8..60fa236 100644 --- a/main.cpp +++ b/main.cpp @@ -108,7 +108,7 @@ GameType check_server_client(int argc, char** argv) { client->create_socket(); /* Send a specific message to the server, and wait for the appropriate response, to know that the server is ready */ client->sendAll("GG"); - std::string msg_from_server = client->recvAll(); + std::string msg_from_server = client->recvAllNB(); if (msg_from_server == "U2") { std::cout << "Connection made. Waiting for server to begin game..." << std::endl; } else { @@ -181,7 +181,7 @@ GameType check_server_client(int argc, char** argv) { int main(int argc, char** argv) { /* Check if game was started in server or client mode, and set appropriate variables */ - /* GameType struct, to define whether the game is in single or muilti-player mode, and + /* GameType struct, to define whether the game is in single or multi-player mode, and to hold the appropriate socket */ GameType type; @@ -322,9 +322,13 @@ int main(int argc, char** argv) { type = check_server(ip_text, port_text); } catch (int e) { display_and_exit(std::string(std::strerror(e)) + "\nClosing game...", 2); // The server constructor throws the errno if it cannot create a socket + free(ip_text); + free(port_text); return -1; } catch (std::invalid_argument& inv) { display_and_exit(std::string(inv.what()) + "\nClosing game...", 2); + free(ip_text); + free(port_text); return -1; } free(ip_text); @@ -359,6 +363,9 @@ int main(int argc, char** argv) { } catch (int e) { display_and_exit(std::string(std::strerror(e)) + "\nClosing game...", 2); // The client constructor throws the errno if it cannot create a socket return -1; + } catch (std::invalid_argument& inv) { + display_and_exit(std::string(inv.what()) + "\nClosing game...", 2); + return -1; } free(code_text); }