Advertisement
Guest User

Untitled

a guest
Jun 19th, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.96 KB | None | 0 0
  1. /**
  2.  * Run Server of PAIR Pattern.
  3.  *
  4.  * $ clang++ pair_server.cpp -lzmq -o pair_server.exe
  5.  */
  6. #include <zmq.hpp>
  7. #include <chrono>
  8. #include <iostream>
  9. #include <cstdlib>
  10. #include <unistd.h>
  11. #include <sys/wait.h>
  12.  
  13. int s_send(void *socket, char *string)
  14. {
  15.     int size = zmq_send(socket, string, strlen(string), 0);
  16.     return size;
  17. }
  18.  
  19. int s_recv(void *socket, char buffer[])
  20. {
  21.     int size = zmq_recv(socket, buffer, 255, 0);
  22.     return size;
  23. }
  24.  
  25. int run(void)
  26. {
  27.     std::cout << "Starting PAIR Server.\n";
  28.     void* context = zmq_ctx_new();
  29.     void* publisher = zmq_socket(context, ZMQ_PAIR);
  30.     auto const rc = zmq_bind(publisher, "tcp://127.0.0.1:5556");
  31.     assert(rc == 0);
  32.     while (1) {
  33.         char message[255] = "Hello AVK!";
  34.         s_send(publisher, message);
  35.     }
  36.     zmq_close(publisher);
  37.     zmq_ctx_destroy(context);
  38.     std::cout << "Finished.\n";
  39.     return 0;
  40. }
  41.  
  42. int main(void)
  43. {
  44.     run();
  45.     return EXIT_SUCCESS;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement