Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
documentation on how to define colors for triva
[simgrid.git] / doc / gtut-files / 02-simple.c
1 #include <stdio.h>
2 #include <gras.h>
3
4 int server(int argc, char *argv[]) {
5   gras_socket_t mysock;   /* socket on which I listen */
6   gras_socket_t toclient; /* socket used to write to the client */
7   
8   gras_init(&argc,argv);
9
10   gras_msgtype_declare("hello", NULL);
11   mysock = gras_socket_server(12345);
12
13   gras_msg_wait(60, "hello", &toclient, NULL /* no payload */);
14   
15   fprintf(stderr,"Cool, we received the message from %s:%d.\n",
16           gras_socket_peer_name(toclient), gras_socket_peer_port(toclient));
17   
18   gras_exit();
19   return 0;
20 }
21 int client(int argc, char *argv[]) {
22   gras_socket_t mysock;   /* socket on which I listen */
23   gras_socket_t toserver; /* socket used to write to the server */
24
25   gras_init(&argc,argv);
26
27   gras_msgtype_declare("hello", NULL);
28   mysock = gras_socket_server_range(1024, 10000, 0, 0);
29   
30   fprintf(stderr,"Client ready; listening on %d\n", gras_socket_my_port(mysock));
31   
32   gras_os_sleep(1.5); /* sleep 1 second and half */
33   toserver = gras_socket_client("Jacquelin", 12345);
34   
35   gras_msg_send(toserver,"hello", NULL);
36   fprintf(stderr,"That's it, we sent the data to the server\n");
37
38   gras_exit();
39   return 0;
40 }