req-rep-basic-client.cpp 732 Bytes
#include <zmq.hpp>
#include <string>
#include <iostream>

int main ()
{
    zmq::context_t context (1);
    zmq::socket_t socket (context, zmq::socket_type::req);

    std::cout << "Connecting to hello world server..." << std::endl;
    socket.connect ("tcp://localhost:5555");

    for (int request_nbr = 0; request_nbr != 10; request_nbr++) {
        zmq::message_t request (5);
        memcpy (request.data (), "Hello", 5);
        std::cout << "Sending request " << request_nbr << "..." << std::endl;
        socket.send (request, zmq::send_flags::none);

        zmq::message_t reply;
        socket.recv (reply, zmq::recv_flags::none);
        std::cout << "Received reply " << request_nbr << std::endl;
    }
    return 0;
}