Go to the documentation of this file.00001
00004
00005
00006
00007
00008 #include <assert.h>
00009 #include <cstdio>
00010 #include <ctime>
00011 #include <cstring>
00012 #include <unistd.h>
00013 #include <nanomsg/nn.h>
00014 #include <nanomsg/pair.h>
00015 #include <iostream>
00016
00017
00018 #define SOCKET_ADDRESS "inproc://a"
00019
00020 void test_recv(int sock, const char *data) {
00021 size_t data_length;
00022 void* buf = NULL;
00023 data_length = strlen(data);
00024 int bytes;
00025 bytes = nn_recv(sock, &buf, NN_MSG, 0);
00026 printf ("Socket %d EXPECTED %s RECEIVED %s [%d bytes]\n", sock, data, (char*)buf, bytes);
00027 nn_freemsg(buf);
00028 }
00029
00030 int main ()
00031 {
00032 int sb;
00033 int sc;
00034
00035 sb = nn_socket (AF_SP, NN_PAIR);
00036 nn_bind (sb, SOCKET_ADDRESS);
00037 sc = nn_socket (AF_SP, NN_PAIR);
00038 nn_connect (sc, SOCKET_ADDRESS);
00039
00040 nn_send (sc, "ABC", 3, 0);
00041 test_recv (sb, "ABC");
00042 nn_send (sb, "DEF", 3, 0);
00043 test_recv (sc, "DEF");
00044
00045 nn_close (sc);
00046 nn_close (sb);
00047
00048 return 0;
00049 }