-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathclient.cpp
40 lines (32 loc) · 1.18 KB
/
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
37
38
39
40
#include "zmq.hpp"
#include "message.pb.h"
#include <string>
#include <iostream>
int main ()
{
GOOGLE_PROTOBUF_VERIFY_VERSION;
tutorial::Person person;
person.set_id(1234);
person.set_name("john");
person.set_email("[email protected]");
tutorial::Person::PhoneNumber* phone_number = person.add_phone();
phone_number->set_number("1234567");
phone_number->set_type(tutorial::Person::MOBILE);
phone_number = person.add_phone();
phone_number->set_number("7654321");
phone_number->set_type(tutorial::Person::HOME);
// Prepare our context and socket
zmq::context_t context (1);
zmq::socket_t socket (context, ZMQ_PAIR);
std::cout << "Connecting to hello world server…" << std::endl;
socket.connect ("tcp://localhost:5555");
std::string msg_str;
person.SerializeToString(&msg_str);
zmq::message_t request (msg_str.size());
memcpy ((void *) request.data (), msg_str.c_str(), msg_str.size());
std::cout << "Sending Person data ..." << std::endl;
socket.send (request);
// Optional: Delete all global objects allocated by libprotobuf.
google::protobuf::ShutdownProtobufLibrary();
return 0;
}