3 int server_hello_cb(gras_msg_cb_ctx_t ctx, void *payload) {
4 gras_socket_t client = gras_msg_cb_ctx_from(ctx);
6 fprintf(stderr,"Cool, we received the message from %s:%d.\n",
7 gras_socket_peer_name(client), gras_socket_peer_port(client));
10 } /* end_of_callback */
12 int server(int argc, char *argv[]) {
13 gras_socket_t mysock; /* socket on which I listen */
14 gras_socket_t toclient; /* socket used to write to the client */
16 gras_init(&argc,argv);
18 gras_msgtype_declare("hello", NULL);
19 mysock = gras_socket_server(atoi(argv[1]));
21 gras_cb_register(gras_msgtype_by_name("hello"),&server_hello_cb);
28 int client(int argc, char *argv[]) {
29 gras_socket_t mysock; /* socket on which I listen */
30 gras_socket_t toserver; /* socket used to write to the server */
32 gras_init(&argc,argv);
34 gras_msgtype_declare("hello", NULL);
35 mysock = gras_socket_server_range(1024, 10000, 0, 0);
37 fprintf(stderr,"Client ready; listening on %d\n", gras_socket_my_port(mysock));
39 gras_os_sleep(1.5); /* sleep 1 second and half */
40 toserver = gras_socket_client(argv[1], atoi(argv[2]));
42 gras_msg_send(toserver,gras_msgtype_by_name("hello"), NULL);
43 fprintf(stderr,"That's it, we sent the data to the server on %s\n", gras_socket_peer_name(toserver));