@@ -11,41 +11,25 @@ int main()
1111
1212 // construct a REQ (request) socket and connect to interface
1313 zmq::socket_t socket{ context, zmq::socket_type::req };
14- socket.connect (" tcp://localhost :5555" );
14+ socket.connect (" tcp://127.0.0.1 :5555" );
1515
1616 // set up some static data to send
1717 const std::string senderName{ " Client" };
18- int32_t pingCount = 0 ;
19- int32_t pongCount = 0 ;
2018
21- for (;;) {
22- // send the request message
23- own::proto::Event event;
24- event.set_sender (senderName);
25- event.set_action (own::proto::Event::PONG);
26- event.set_ping_count (pingCount);
27- event.set_pong_count (pongCount);
28-
29- std::string data;
30- event.SerializeToString (&data);
19+ zmq::message_t request{};
20+ // send the request message
21+ auto [sendEvent, serializedData] = Common::prepareMessage (senderName, request);
3122
23+ for (;;) {
3224 // send to the server
33- socket.send (zmq::buffer (data ), zmq::send_flags::none);
25+ socket.send (zmq::buffer (serializedData ), zmq::send_flags::none);
3426
3527 // wait for reply from server
36- zmq::message_t reply{};
37- socket.recv (reply, zmq::recv_flags::none);
38-
39- own::proto::Event receivedEvent;
40- receivedEvent.ParseFromArray (reply.data (), static_cast <int >(reply.size ()));
41- pingCount = receivedEvent.ping_count ();
42- pongCount = receivedEvent.pong_count () + 1 ;
43-
44- spdlog::info (" Received from: {} Action: {} Ping count: {} Pong count: {}" ,
45- receivedEvent.sender (),
46- own::proto::Event_PingPong_Name (receivedEvent.action ()),
47- receivedEvent.ping_count (),
48- receivedEvent.pong_count ());
28+ socket.recv (request, zmq::recv_flags::none);
29+ const auto [receivedEvent, _] = Common::prepareMessage (senderName, request);
30+ serializedData = Common::incrementPingPong (sendEvent, own::proto::Event::PONG);
31+ sendEvent = receivedEvent;
32+ Common::logProtoEvent (receivedEvent);
4933
5034 if (receivedEvent.pong_count () == Common::maxCount) { break ; }
5135 }
0 commit comments