-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathzmq_client.cpp
36 lines (29 loc) · 962 Bytes
/
zmq_client.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// from: https://zeromq.org/get-started/?language=cpp&library=zmqpp#
// Hello World client
#include <zmqpp/zmqpp.hpp>
#include <string>
#include <iostream>
using namespace std;
int main(int argc, char *argv[]) {
const string endpoint = "tcp://10.0.1.87:5555";
// initialize the 0MQ context
zmqpp::context context;
// generate a push socket
zmqpp::socket_type type = zmqpp::socket_type::req;
zmqpp::socket socket (context, type);
// open the connection
cout << "Connecting to hello world server…" << endl;
socket.connect(endpoint);
int request_nbr;
for (request_nbr = 0; request_nbr != 10; request_nbr++) {
// send a message
cout << "Sending Hello " << request_nbr <<"..." << endl;
zmqpp::message message;
// compose a message from a string and a number
message << "Hello";
socket.send(message);
string buffer;
socket.receive(buffer);
cout << "Received World " << request_nbr << endl;
}
}