|
|
@ -40,6 +40,7 @@ |
|
|
|
#include <grpc++/server_builder.h> |
|
|
|
#include <grpc++/server_builder.h> |
|
|
|
#include <grpc++/server_context.h> |
|
|
|
#include <grpc++/server_context.h> |
|
|
|
#include <grpc++/server_credentials.h> |
|
|
|
#include <grpc++/server_credentials.h> |
|
|
|
|
|
|
|
|
|
|
|
#include "helloworld.grpc.pb.h" |
|
|
|
#include "helloworld.grpc.pb.h" |
|
|
|
|
|
|
|
|
|
|
|
using grpc::Server; |
|
|
|
using grpc::Server; |
|
|
@ -50,6 +51,7 @@ using helloworld::HelloRequest; |
|
|
|
using helloworld::HelloReply; |
|
|
|
using helloworld::HelloReply; |
|
|
|
using helloworld::Greeter; |
|
|
|
using helloworld::Greeter; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Logic and data behind the server's behavior.
|
|
|
|
class GreeterServiceImpl final : public Greeter::Service { |
|
|
|
class GreeterServiceImpl final : public Greeter::Service { |
|
|
|
Status SayHello(ServerContext* context, const HelloRequest* request, |
|
|
|
Status SayHello(ServerContext* context, const HelloRequest* request, |
|
|
|
HelloReply* reply) override { |
|
|
|
HelloReply* reply) override { |
|
|
@ -64,10 +66,17 @@ void RunServer() { |
|
|
|
GreeterServiceImpl service; |
|
|
|
GreeterServiceImpl service; |
|
|
|
|
|
|
|
|
|
|
|
ServerBuilder builder; |
|
|
|
ServerBuilder builder; |
|
|
|
|
|
|
|
// Listen on the given address without any authentication mechanism.
|
|
|
|
builder.AddListeningPort(server_address, grpc::InsecureServerCredentials()); |
|
|
|
builder.AddListeningPort(server_address, grpc::InsecureServerCredentials()); |
|
|
|
|
|
|
|
// Register "service" as the instance through which we'll communicate with
|
|
|
|
|
|
|
|
// clients. In this case it corresponds to an *synchronous* service.
|
|
|
|
builder.RegisterService(&service); |
|
|
|
builder.RegisterService(&service); |
|
|
|
|
|
|
|
// Finally assemble the server.
|
|
|
|
std::unique_ptr<Server> server(builder.BuildAndStart()); |
|
|
|
std::unique_ptr<Server> server(builder.BuildAndStart()); |
|
|
|
std::cout << "Server listening on " << server_address << std::endl; |
|
|
|
std::cout << "Server listening on " << server_address << std::endl; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Wait for the server to shutdown. Note that some other thread must be
|
|
|
|
|
|
|
|
// responsible for shutting down the server for this call to ever return.
|
|
|
|
server->Wait(); |
|
|
|
server->Wait(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|