Used the non-blocking recv function, to ensure that the game doesn't hang if the server doesn't respond.

master
Aadhavan Srinivasan 7 months ago
parent 839efc3c44
commit 00d20ebc88

@ -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;

Loading…
Cancel
Save