Created
March 3, 2020 18:47
-
-
Save Warwolt/0c33e2013f8d80d6d8912331cde6130a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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