int client(int argc,char *argv[]) {
xbt_ex_t e;
gras_socket_t toserver=NULL; /* peer */
+ int connected = 0;
gras_socket_t from;
int ping, pong;
gras_os_sleep(1);
/* 4. Create a socket to speak to the server */
- TRY {
- toserver=gras_socket_client(host,port);
- } CATCH(e) {
- RETHROW0("Unable to connect to the server: %s");
+ while (!connected) {
+ TRY {
+ toserver=gras_socket_client(host,port);
+ connected = 1;
+ } CATCH(e) {
+ if (e.category != system_error)
+ /* dunno what happened, let the exception go through */
+ RETHROW0("Unable to connect to the server: %s");
+ xbt_ex_free(e);
+ gras_os_sleep(0.05);
+ }
}
- INFO2("Connected to %s:%d.",host,port);
+ INFO2("Connected to %s:%d.",host,port);
/* 5. Register the messages.
See, it doesn't have to be done completely at the beginning, only before use */
/* 10. Free the allocated resources, and shut GRAS down */
gras_socket_close(toserver);
- gras_exit();
INFO0("Done.");
+ gras_exit();
return 0;
} /* end_of_client */