Advertisement
Guest User

rep

a guest
Dec 17th, 2012
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <algorithm>
  2. #include <zmq.hpp>
  3. #include <iostream>
  4.  
  5. int main() {
  6.     zmq::context_t  ctx(1);
  7.  
  8.     zmq::socket_t s(ctx, ZMQ_REP);
  9.     s.bind("tcp://127.0.0.1:5555");
  10.  
  11.     while (true) {
  12.         zmq_pollitem_t items[] = {{static_cast<void *>(s), 0, ZMQ_POLLIN, 0}};
  13.         zmq::poll(items, 1, -1);
  14.         if (items->revents & ZMQ_POLLIN) {
  15.             bool cont = false;
  16.             bool z = true;
  17.             std::string nb;
  18.             do {
  19.                 zmq::message_t m;
  20.                 s.recv(&m);
  21.                 if (z) {
  22.                     nb.assign(static_cast<char *>(m.data()), m.size());
  23.                 }
  24.                 int64_t more = 0;
  25.                 size_t more_size = sizeof(more);
  26.                 s.getsockopt(ZMQ_RCVMORE, &more, &more_size);
  27.                 cont = more;
  28.             } while (cont);
  29.             std::cout << "got nb " << nb << std::endl;
  30.             {
  31.                 zmq::message_t m;
  32.                 s.send(m);
  33.             }
  34.             zmq::socket_t s_new(ctx, ZMQ_REQ);
  35.             s_new.connect("tcp://127.0.0.1:5556");
  36.             {
  37.                 zmq::message_t m;
  38.                 s_new.send(m);
  39.             }
  40.             {
  41.                 zmq::message_t m;
  42.                 s_new.recv(&m);
  43.             }
  44.         }
  45.     }
  46.     return EXIT_SUCCESS;
  47.  
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement