-
Notifications
You must be signed in to change notification settings - Fork 2
/
example_server.cc
54 lines (43 loc) · 1.47 KB
/
example_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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*************************************************************************
> File Name: example_client.cc
> Author: Zhaohb
> Mail: zhaohongbo@inspur.com
> Created Time: Tue 26 Feb 2019 01:59:53 PM CST
************************************************************************/
#include<iostream>
using namespace std;
#include <iostream>
#include <memory>
#include <string>
#include <grpc++/grpc++.h>
#include <grpc/grpc.h>
#include <grpc++/server.h>
#include <grpc++/server_builder.h>
#include <grpc++/server_context.h>
#include "example.grpc.pb.h"
using grpc::Server;
using grpc::ServerBuilder;
using grpc::ServerContext;
using grpc::Status;
class SearchRequestImpl final : public SearchService::Service {
Status Search(ServerContext* context, const SearchRequest* request,
SearchResponse* reply) override {
std::string prefix("Hello ");
reply->set_response(prefix + request->request());
return Status::OK;
}
};
void RunServer() {
std::string server_address("0.0.0.0:50051");
SearchRequestImpl service;
ServerBuilder builder;
builder.AddListeningPort(server_address, grpc::InsecureServerCredentials());
builder.RegisterService(&service);
std::unique_ptr<Server> server(builder.BuildAndStart());
std::cout << "Server listening on " << server_address << std::endl;
server->Wait();
}
int main(int argc, char** argv) {
RunServer();
return 0;
}