Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <algorithm>
- #include <zmq.hpp>
- #include <iostream>
- int main() {
- zmq::context_t ctx(1);
- zmq::socket_t s(ctx, ZMQ_REP);
- s.bind("tcp://127.0.0.1:5555");
- while (true) {
- zmq_pollitem_t items[] = {{static_cast<void *>(s), 0, ZMQ_POLLIN, 0}};
- zmq::poll(items, 1, -1);
- if (items->revents & ZMQ_POLLIN) {
- bool cont = false;
- bool z = true;
- std::string nb;
- do {
- zmq::message_t m;
- s.recv(&m);
- if (z) {
- nb.assign(static_cast<char *>(m.data()), m.size());
- }
- int64_t more = 0;
- size_t more_size = sizeof(more);
- s.getsockopt(ZMQ_RCVMORE, &more, &more_size);
- cont = more;
- } while (cont);
- std::cout << "got nb " << nb << std::endl;
- {
- zmq::message_t m;
- s.send(m);
- }
- zmq::socket_t s_new(ctx, ZMQ_REQ);
- s_new.connect("tcp://127.0.0.1:5556");
- {
- zmq::message_t m;
- s_new.send(m);
- }
- {
- zmq::message_t m;
- s_new.recv(&m);
- }
- }
- }
- return EXIT_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement