Advertisement
Guest User

Untitled

a guest
Jul 17th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.17 KB | None | 0 0
  1. CLIENT:
  2. #include <czmq.h>
  3.  
  4. int main (void)
  5. {
  6.     zsock_t *pub, *sub;
  7.     pub = zsock_new_pub(">tcp://localhost:5555");
  8.     zmsg_t *send = zmsg_new();
  9.     zframe_t *f1, *f2;
  10.     f1 = zframe_new("/test/test2",strlen("/test/test2"));
  11.     f2 = zframe_new("Hello, world",strlen("Hello, world"));
  12.     zmsg_append(send,&f1);
  13.     zmsg_append(send,&f2);
  14.     zmsg_send(&send,pub);
  15.     sub = zsock_new_sub(">tcp://localhost:5556", "/test/test2");
  16.     sleep(1);
  17.     zmsg_t *msg = zmsg_recv(sub);
  18.     zmsg_print(msg);
  19.     zmsg_destroy(&msg);
  20.     zsock_destroy(&pub);
  21.     zsock_destroy(&sub);
  22.     return 0;
  23. }
  24.  
  25. SERVER:
  26. #include <czmq.h>
  27.  
  28. int main (void)
  29. {
  30.     zactor_t *proxy = zactor_new(zproxy, NULL);
  31.     zstr_send (proxy, "VERBOSE");
  32.     zsock_wait (proxy);
  33.     zstr_sendx(proxy, "FRONTEND", "XSUB", "tcp://*:5555", NULL);
  34.     zsock_wait(proxy);
  35.     zstr_sendx(proxy, "BACKEND", "XPUB", "tcp://*:5556", NULL);
  36.     zsock_wait(proxy);
  37.     zsock_t *capture = zsock_new_pull ("inproc://capture");
  38.     zstr_sendx (proxy, "CAPTURE", "inproc://capture", NULL);
  39.     zsock_wait (proxy);
  40.  
  41.     while (true) {
  42.         zmsg_t *msg = zmsg_recv(capture);
  43.         if (!msg)
  44.             break;
  45.         printf("C: ");
  46.         zmsg_print(msg);
  47.     }
  48.     zsock_destroy(&capture);
  49.     zactor_destroy(&proxy);
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement