2016-06-03 19:34:09 +02:00
|
|
|
#include <string>
|
2016-07-14 18:53:28 +02:00
|
|
|
#include <iostream>
|
|
|
|
#include <atomic>
|
2016-06-03 19:34:09 +02:00
|
|
|
|
|
|
|
#include <grpc++/grpc++.h>
|
|
|
|
#include "echo.grpc.pb.h"
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
using grpc::Server;
|
|
|
|
using grpc::ServerBuilder;
|
|
|
|
using grpc::ServerContext;
|
|
|
|
using grpc::Status;
|
|
|
|
|
2016-07-21 21:55:16 +02:00
|
|
|
using namespace echo;
|
2016-06-03 19:34:09 +02:00
|
|
|
|
2016-07-14 18:53:28 +02:00
|
|
|
atomic_int reqCount;
|
|
|
|
|
2016-06-03 19:34:09 +02:00
|
|
|
class EchoServiceImpl final : public Echo::Service {
|
|
|
|
Status DoEcho(ServerContext* ctx, const EchoRequest* req,
|
|
|
|
EchoRequest* resp) override {
|
|
|
|
resp->set_message(req->message());
|
|
|
|
return Status::OK;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-07-21 21:55:16 +02:00
|
|
|
class AddServiceImpl final : public Add::Service {
|
|
|
|
Status DoAdd(ServerContext* ctx, const AddRequest* req,
|
|
|
|
AddResponse* resp) override {
|
|
|
|
resp->set_answer(req->addx() + req->addy());
|
|
|
|
return Status::OK;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-06-03 19:34:09 +02:00
|
|
|
int main(){
|
|
|
|
string server_address("localhost:50051");
|
2016-07-21 21:55:16 +02:00
|
|
|
EchoServiceImpl echoService;
|
|
|
|
AddServiceImpl addService;
|
2016-06-03 19:34:09 +02:00
|
|
|
|
|
|
|
ServerBuilder builder;
|
|
|
|
builder.AddListeningPort(server_address, grpc::InsecureServerCredentials());
|
2016-07-21 21:55:16 +02:00
|
|
|
builder.RegisterService(&echoService);
|
|
|
|
builder.RegisterService(&addService);
|
2016-06-03 19:34:09 +02:00
|
|
|
unique_ptr<Server> server(builder.BuildAndStart());
|
|
|
|
server->Wait();
|
|
|
|
return 0;
|
|
|
|
}
|