Replaced recvAll call with recvAllNB
This commit is contained in:
11
main.cpp
11
main.cpp
@@ -108,7 +108,7 @@ GameType check_server_client(int argc, char** argv) {
|
|||||||
client->create_socket();
|
client->create_socket();
|
||||||
/* Send a specific message to the server, and wait for the appropriate response, to know that the server is ready */
|
/* Send a specific message to the server, and wait for the appropriate response, to know that the server is ready */
|
||||||
client->sendAll("GG");
|
client->sendAll("GG");
|
||||||
std::string msg_from_server = client->recvAll();
|
std::string msg_from_server = client->recvAllNB();
|
||||||
if (msg_from_server == "U2") {
|
if (msg_from_server == "U2") {
|
||||||
std::cout << "Connection made. Waiting for server to begin game..." << std::endl;
|
std::cout << "Connection made. Waiting for server to begin game..." << std::endl;
|
||||||
} else {
|
} else {
|
||||||
@@ -181,7 +181,7 @@ GameType check_server_client(int argc, char** argv) {
|
|||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
/* Check if game was started in server or client mode, and set appropriate variables */
|
/* 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 */
|
to hold the appropriate socket */
|
||||||
GameType type;
|
GameType type;
|
||||||
|
|
||||||
@@ -322,9 +322,13 @@ int main(int argc, char** argv) {
|
|||||||
type = check_server(ip_text, port_text);
|
type = check_server(ip_text, port_text);
|
||||||
} catch (int e) {
|
} 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
|
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;
|
return -1;
|
||||||
} catch (std::invalid_argument& inv) {
|
} catch (std::invalid_argument& inv) {
|
||||||
display_and_exit(std::string(inv.what()) + "\nClosing game...", 2);
|
display_and_exit(std::string(inv.what()) + "\nClosing game...", 2);
|
||||||
|
free(ip_text);
|
||||||
|
free(port_text);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
free(ip_text);
|
free(ip_text);
|
||||||
@@ -359,6 +363,9 @@ int main(int argc, char** argv) {
|
|||||||
} catch (int e) {
|
} 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
|
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;
|
return -1;
|
||||||
|
} catch (std::invalid_argument& inv) {
|
||||||
|
display_and_exit(std::string(inv.what()) + "\nClosing game...", 2);
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
free(code_text);
|
free(code_text);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user