1 /* Copyright (c) 2006, 2007, 2010. The SimGrid Team.
2 * All rights reserved. */
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. */
10 int server_hello_cb(gras_msg_cb_ctx_t ctx, void *payload) {
11 gras_socket_t client = gras_msg_cb_ctx_from(ctx);
13 fprintf(stderr,"Cool, we received the message from %s:%d.\n",
14 gras_socket_peer_name(client), gras_socket_peer_port(client));
17 } /* end_of_callback */
19 int server(int argc, char *argv[]) {
20 gras_socket_t mysock; /* socket on which I listen */
22 gras_init(&argc,argv);
24 gras_msgtype_declare("hello", NULL);
25 mysock = gras_socket_server(atoi(argv[1]));
27 gras_cb_register("hello",&server_hello_cb);
34 int client(int argc, char *argv[]) {
35 gras_socket_t mysock; /* socket on which I listen */
36 gras_socket_t toserver; /* socket used to write to the server */
38 gras_init(&argc,argv);
40 gras_msgtype_declare("hello", NULL);
41 mysock = gras_socket_server_range(1024, 10000, 0, 0);
43 fprintf(stderr,"Client ready; listening on %d\n", gras_socket_my_port(mysock));
45 gras_os_sleep(1.5); /* sleep 1 second and half */
46 toserver = gras_socket_client(argv[1], atoi(argv[2]));
48 gras_msg_send(toserver,"hello", NULL);
49 fprintf(stderr,"That's it, we sent the data to the server on %s\n", gras_socket_peer_name(toserver));