This repository has been archived on 2024-12-15. You can view files and clone it, but cannot push or open issues or pull requests.
ProtoBufTest/Client/Client.cpp

38 lines
794 B
C++
Raw Normal View History

2015-02-19 13:59:22 +00:00
#include <iostream>
2015-02-22 19:29:32 +00:00
#include <string>
2015-02-19 13:59:22 +00:00
#include <zmq.hpp>
#include "proto/request.pb.h"
#include "proto/reply.pb.h"
2015-02-22 19:18:51 +00:00
2015-02-19 13:59:22 +00:00
int main(int argc, char **argv)
{
std::cout << "Client running" << std::endl;
zmq::context_t context(1);
zmq::socket_t socket(context, ZMQ_REQ);
socket.connect("tcp://localhost:5555");
while (true)
{
Messages::Request requestMessage;
requestMessage.set_text("Hello Server");
zmq::message_t request(requestMessage.ByteSize());
requestMessage.SerializeToArray(request.data(), request.size());
socket.send(request);
2015-02-22 19:29:32 +00:00
zmq::message_t reply;
socket.recv(&reply);
2015-02-22 19:29:32 +00:00
Messages::Reply replyMessage;
replyMessage.ParseFromArray(reply.data(), reply.size());
2015-02-22 19:29:32 +00:00
std::cout << "Received reply: " << replyMessage.text() << std::endl;
2015-02-22 19:29:32 +00:00
Sleep(1000);
}
2015-02-22 19:29:32 +00:00
2015-02-19 13:59:22 +00:00
return 0;
}