Guest User

zeromq_epgm_sub.c

a guest
Aug 1st, 2013
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.70 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdint.h>
  3. #include <stdio.h>
  4. #include <stdbool.h>
  5. #include <string.h>
  6. #include <czmq.h>
  7. #include <assert.h>
  8.  
  9. #define LISTEN_SOCK "epgm://239.77.77.77:5556"
  10.  
  11. int main(void)
  12. {
  13.     zctx_t *zmq_context = zctx_new();
  14.     void *zsocket = zsocket_new (zmq_context, ZMQ_SUB);
  15.     assert (zsocket);
  16.         zsockopt_set_hwm(zsocket, 10);
  17.     assert (zsocket_connect (zsocket, LISTEN_SOCK) == 0);
  18.     zsocket_set_subscribe(zsocket, "MESSAGE");
  19.  
  20.         char *msg;
  21.         while ( (msg = zstr_recv(zsocket))) {
  22.                 printf ("%s\n", msg);
  23.                 free(msg);
  24.         }
  25.  
  26.         zsocket_destroy(zmq_context, zsocket);
  27.         zctx_destroy(&zmq_context);
  28.  
  29.     return 0;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment