diff options
Diffstat (limited to 'src/game.c')
| -rw-r--r-- | src/game.c | 16 |
1 files changed, 13 insertions, 3 deletions
@@ -137,12 +137,22 @@ void start_game(const bool servermode, const char* addr, const char* port, const { int sock; - sleep(1); // TODO make sure server process is listening - if(addr == NULL) addr = "localhost"; - sock = client_connect_server(addr, port); + for(int i=0; i<5; i++) // try to connect 5 times + { + sock = client_connect_server(addr, port); + if(sock != -1) + break; + usleep(300000); // wait 300 ms before retry + } + if(sock == -1) + { + fprintf(stderr, "Connection refused\n"); + exit(EXIT_FAILURE); + } + data_store_t *data = data_store(); net_send(sock, msg_type_hello_c, NULL); |
