Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
make so that the tester builders are trigered when makeDist one is done
[simgrid.git] / examples / gras / ping / ping_client.c
index 2afae4b..6230b70 100644 (file)
@@ -13,6 +13,7 @@ XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(Ping);
 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;
@@ -35,13 +36,20 @@ int client(int argc,char *argv[]) {
   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 */
@@ -54,7 +62,7 @@ int client(int argc,char *argv[]) {
   /* 7. Prepare and send the ping message to the server */
   ping = 1234;
   TRY {
-    gras_msg_send(toserver, gras_msgtype_by_name("ping"), &ping);
+    gras_msg_send(toserver, "ping", &ping);
   } CATCH(e) {
     gras_socket_close(toserver);
     RETHROW0("Failed to send PING to server: %s");
@@ -65,8 +73,7 @@ int client(int argc,char *argv[]) {
 
   /* 8. Wait for the answer from the server, and deal with issues */
   TRY {
-    gras_msg_wait(6000,gras_msgtype_by_name("pong"),
-                 &from,&pong);
+    gras_msg_wait(6000,"pong", &from,&pong);
   } CATCH(e) {
     gras_socket_close(toserver);
     RETHROW0("Why can't I get my PONG message like everyone else: %s");
@@ -79,7 +86,7 @@ int client(int argc,char *argv[]) {
 
   /* 10. Free the allocated resources, and shut GRAS down */
   gras_socket_close(toserver);
-  gras_exit();
   INFO0("Done.");
+  gras_exit();
   return 0;
 } /* end_of_client */