Used the non-blocking recv function, to ensure that the game doesn't hang if the server doesn't respond.
This commit is contained in:
@@ -62,14 +62,13 @@ GameType check_client(char* code_text) {
|
||||
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");
|
||||
// display_text_centered("Connecting...");
|
||||
std::string msg_from_server = client->recvAll();
|
||||
std::string msg_from_server = client->recvAllNB();
|
||||
if (msg_from_server == "U2") {
|
||||
display_text_centered("Connection made");
|
||||
Timer timer = timer_init(3);
|
||||
while (!timer_done(timer));
|
||||
} else {
|
||||
throw EXCEPT_WRONGRESPONSE;
|
||||
throw std::invalid_argument("Server didn't respond with correct message.");
|
||||
}
|
||||
type.mode = M_CLIENT;
|
||||
type.netsock = client;
|
||||
|
Reference in New Issue
Block a user