Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix the path to gras_stub_generator in the tutorial makefile
[simgrid.git] / doc / gtut-files / 03-args.c
1 /* Copyright (c) 2006, 2007, 2010. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5   * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 #include <stdio.h>
8 #include <gras.h>
9
10 int server(int argc, char *argv[]) {
11   gras_socket_t mysock;   /* socket on which I listen */
12   gras_socket_t toclient; /* socket used to write to the client */
13   
14   gras_init(&argc,argv);
15
16   gras_msgtype_declare("hello", NULL);
17   mysock = gras_socket_server(atoi(argv[1]));
18
19   gras_msg_wait(60, "hello", &toclient, NULL /* no payload */);
20   
21   fprintf(stderr,"Cool, we received the message from %s:%d.\n",
22           gras_socket_peer_name(toclient), gras_socket_peer_port(toclient));
23   
24   gras_exit();
25   return 0;
26 }
27 int client(int argc, char *argv[]) {
28   gras_socket_t mysock;   /* socket on which I listen */
29   gras_socket_t toserver; /* socket used to write to the server */
30
31   gras_init(&argc,argv);
32
33   gras_msgtype_declare("hello", NULL);
34   mysock = gras_socket_server_range(1024, 10000, 0, 0);
35   
36   fprintf(stderr,"Client ready; listening on %d\n", gras_socket_my_port(mysock));
37   
38   gras_os_sleep(1.5); /* sleep 1 second and half */
39   toserver = gras_socket_client(argv[1], atoi(argv[2]));
40   
41   gras_msg_send(toserver,"hello", NULL);
42   fprintf(stderr,"That's it, we sent the data to the server on %s\n", gras_socket_peer_name(toserver));
43
44   gras_exit();
45   return 0;
46 }