nanomsg_radio.cpp
Go to the documentation of this file.
1 
4 /*****************************************************************************
5 ** Includes
6 *****************************************************************************/
7 
8 #include <assert.h>
9 #include <cstdio>
10 #include <ctime>
11 #include <cstring>
12 #include <unistd.h>
13 #include <nanomsg/nn.h>
14 #include <nanomsg/pair.h>
15 #include <iostream>
16 
17 
18 #define SOCKET_ADDRESS "inproc://a"
19 
20 void test_recv(int sock, const char *data) {
21  size_t data_length;
22  void* buf = NULL;
23  data_length = strlen(data);
24  int bytes;
25  bytes = nn_recv(sock, &buf, NN_MSG, 0);
26  printf ("Socket %d EXPECTED %s RECEIVED %s [%d bytes]\n", sock, data, (char*)buf, bytes);
27  nn_freemsg(buf);
28 }
29 
30 int main ()
31 {
32  int sb;
33  int sc;
34 
35  sb = nn_socket (AF_SP, NN_PAIR);
36  nn_bind (sb, SOCKET_ADDRESS);
37  sc = nn_socket (AF_SP, NN_PAIR);
38  nn_connect (sc, SOCKET_ADDRESS);
39 
40  nn_send (sc, "ABC", 3, 0);
41  test_recv (sb, "ABC");
42  nn_send (sb, "DEF", 3, 0);
43  test_recv (sc, "DEF");
44 
45  nn_close (sc);
46  nn_close (sb);
47 
48  return 0;
49 }
#define SOCKET_ADDRESS
void test_recv(int sock, const char *data)
int main()


mm_radio
Author(s): Daniel Stonier
autogenerated on Mon Jun 10 2019 13:52:16