mirror of
https://github.com/unclechu/gRPC-haskell.git
synced 2024-11-27 05:29:43 +01:00
ce56953b24
* 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
34 lines
784 B
C++
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;
|
|
}
|