gRPC-haskell/examples/echo/echo-cpp/echo-server.cc
Connor Clark ce56953b24 Various example/benchmarking code (#16)
* initial echo client/server examples

* registered and unregistered versions of the example client

* ignore pyc files

* cpp echo code, flag to build examples

* threaded server example
2016-06-03 10:34:09 -07:00

34 lines
784 B
C++

#include <string>
#include <grpc++/grpc++.h>
#include "echo.grpc.pb.h"
using namespace std;
using grpc::Server;
using grpc::ServerBuilder;
using grpc::ServerContext;
using grpc::Status;
using echo::EchoRequest;
using echo::Echo;
class EchoServiceImpl final : public Echo::Service {
Status DoEcho(ServerContext* ctx, const EchoRequest* req,
EchoRequest* resp) override {
resp->set_message(req->message());
return Status::OK;
}
};
int main(){
string server_address("localhost:50051");
EchoServiceImpl service;
ServerBuilder builder;
builder.AddListeningPort(server_address, grpc::InsecureServerCredentials());
builder.RegisterService(&service);
unique_ptr<Server> server(builder.BuildAndStart());
server->Wait();
return 0;
}