AirInv Logo  1.00.12
C++ Simulated Airline Inventory Management System Library
Loading...
Searching...
No Matches
AirInvClient.cpp
Go to the documentation of this file.
1// //////////////////////////////////////////////////////////////////////
2// Import section
3// //////////////////////////////////////////////////////////////////////
4// STL
5#include <string>
6#include <iostream>
7// ZeroMQ
8#include <zmq.hpp>
9
10// ////////////////// M A I N /////////////////////
11int main (int argc, char* argv[]) {
12 // Prepare our context and socket
13 zmq::context_t context (1);
14 zmq::socket_t socket (context, ZMQ_REQ);
15
16 std::cout << "Connecting to hello world server…" << std::endl;
17 socket.connect ("tcp://localhost:5555");
18
19 // Do 10 requests, waiting each time for a response
20 for (int request_nbr = 0; request_nbr != 10; request_nbr++) {
21 zmq::message_t request (6);
22 memcpy ((void *) request.data (), "Hello", 5);
23 std::cout << "Sending Hello " << request_nbr << "…" << std::endl;
24
25 zmq::send_flags flags = zmq::send_flags::none;
26 const zmq::send_result_t rcs = socket.send (request, flags);
27
28 // DEBUG
29 if (rcs.has_value()) {
30 const unsigned int rcs_val = rcs.value();
31 std::cout << "Result of sending payload: " << rcs_val << std::endl;
32 }
33
34 // Get the reply.
35 zmq::message_t reply;
36 zmq::recv_result_t rcr = socket.recv (reply);
37
38 // DEBUG
39 if (rcr.has_value()) {
40 const unsigned int rcr_val = rcr.value();
41 std::cout << "Receive status: " << rcr_val << std::endl;
42 }
43
44 //
45 std::cout << "Received World " << request_nbr << std::endl;
46 }
47 return 0;
48}
int main(int argc, char *argv[])