Logo AND Algorithmique Numérique Distribuée

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