-
Notifications
You must be signed in to change notification settings - Fork 20
/
sample_server.cc
39 lines (33 loc) · 1.07 KB
/
sample_server.cc
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
#include "sample.grpc.pb.h"
#include <grpc++/grpc++.h>
#include <memory>
#include <iostream>
using grpc::Server;
using grpc::ServerBuilder;
using grpc::ServerContext;
using grpc::Status;
using sample::SampleRequest;
using sample::SampleResponse;
using sample::SampleService;
class SampleServiceImpl final : public SampleService::Service {
Status SampleMethod(ServerContext* context, const SampleRequest* request, SampleResponse* response) override {
response->set_response_sample_field("Hello " + request->request_sample_field());
return Status::OK;
}
};
void RunServer() {
std::string server_address{"localhost:2510"};
SampleServiceImpl service;
// Build server
ServerBuilder builder;
builder.AddListeningPort(server_address, grpc::InsecureServerCredentials());
builder.RegisterService(&service);
std::unique_ptr<Server> server{builder.BuildAndStart()};
// Run server
std::cout << "Server listening on " << server_address << std::endl;
server->Wait();
}
int main(int argc, char** argv) {
RunServer();
return 0;
}