-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.cc
More file actions
43 lines (34 loc) · 1.02 KB
/
client.cc
File metadata and controls
43 lines (34 loc) · 1.02 KB
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
41
42
43
#include <iomanip>
#include <iostream>
#include <memory>
#include <string>
#include <grpcpp/ext/proto_server_reflection_plugin.h>
#include <grpcpp/grpcpp.h>
#include <grpcpp/health_check_service_interface.h>
#include "proto/testserver.grpc.pb.h"
using grpc::Channel;
using grpc::ClientContext;
using grpc::Status;
class Client {
public:
Client(std::shared_ptr<Channel> channel) : stub_(testserver::Api::NewStub(channel)) {}
void DoThingRequest(void)
{
testserver::DoThingRequest request;
request.set_message("foobar");
testserver::DoThingResponse response;
ClientContext context;
Status status = stub_->DoThing(&context, request, &response);
if (!status.ok()) {
std::cout << status.error_message() << std::endl;
return;
}
std::cout << response.message() << std::endl;
}
private:
std::unique_ptr<testserver::Api::Stub> stub_;
};
int main(int argc, char** argv) {
Client(grpc::CreateChannel("localhost:50051", grpc::InsecureChannelCredentials())).DoThingRequest();
return 0;
}