Skip to content

Instantly share code, notes, and snippets.

@Warwolt
Created March 3, 2020 18:47
Show Gist options
  • Save Warwolt/0c33e2013f8d80d6d8912331cde6130a to your computer and use it in GitHub Desktop.
Save Warwolt/0c33e2013f8d80d6d8912331cde6130a to your computer and use it in GitHub Desktop.
#include <zmq.hpp>
#include <string>
#include <iostream>
int main()
{
std::cout << "client started" << std::endl;
/* Prepare our context and socket */
zmq::context_t context(1);
zmq::socket_t socket(context, ZMQ_REQ);
std::cout << "Connecting to hello world server…" << std::endl;
socket.connect("tcp://localhost:5555");
/* Do 10 requests, waiting each time for a response */
for (int request_nbr = 0; request_nbr != 10; request_nbr++)
{
zmq::message_t request(5);
memcpy(request.data(), "Hello", 5);
std::cout << "Sending Hello " << request_nbr << std::endl;
socket.send(request, zmq::send_flags::dontwait);
/* Get the reply */
zmq::message_t reply;
if (!(socket.recv(reply).has_value()))
{
std::cerr << "Could not receive message!" << std::endl;
}
std::cout << "Received World " << request_nbr << std::endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment