Guest User

zmq puller

a guest
May 7th, 2014
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.81 KB | None | 0 0
  1. //  Hello World client
  2. #include <zmq.h>
  3. #include <string.h>
  4. #include <stdio.h>
  5. #include <unistd.h>
  6.  
  7. int main (int argc, char *argv[])
  8. {
  9.     void *context = zmq_ctx_new ();
  10.     void *puller = zmq_socket (context, ZMQ_PULL);
  11.     int opti = 10000;
  12.  
  13.     zmq_setsockopt (puller, ZMQ_RCVHWM, &opti, sizeof(opti));
  14.     zmq_bind (puller, argc > 1 ? argv[1] : "tcp://*:13006");
  15.  
  16.     if (1) {
  17.     // initialize poll set
  18.     zmq_pollitem_t items[] = { { puller, 0, ZMQ_POLLIN, 0 } };
  19.  
  20.     while (1) {
  21.         zmq_poll(items, 1, -1);
  22.         if (items[0].revents & ZMQ_POLLIN) {
  23.             zmq_msg_t msg;
  24.             zmq_msg_init(&msg);
  25.             zmq_msg_recv(&msg, puller, 0);
  26.             zmq_msg_close(&msg);
  27.         }
  28.     }
  29.     }
  30.  
  31.     zmq_close (puller);
  32.     zmq_ctx_destroy (context);
  33.     return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment