test/distrib/bazel/cpp/greeter_server.cc
Go to the documentation of this file.
1 /*
2  *
3  * Copyright 2022 The gRPC authors.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
19 #include <iostream>
20 #include <memory>
21 #include <string>
22 
24 #include <grpcpp/grpcpp.h>
26 
27 #include "protos/helloworld.grpc.pb.h"
28 
29 using grpc::Server;
32 using grpc::Status;
36 
37 // Logic and data behind the server's behavior.
38 class GreeterServiceImpl final : public Greeter::Service {
40  HelloReply* reply) override {
41  std::string prefix("Hello ");
42  reply->set_message(prefix + request->name());
43  return Status::OK;
44  }
45 };
46 
47 void RunServer() {
48  std::string server_address("0.0.0.0:0");
50 
54  // Listen on the given address without any authentication mechanism.
55  int bound_port;
56  builder.AddListeningPort(server_address, grpc::InsecureServerCredentials(), &bound_port);
57  // Register "service" as the instance through which we'll communicate with
58  // clients. In this case it corresponds to an *synchronous* service.
59  builder.RegisterService(&service);
60  // Finally assemble the server.
61  std::unique_ptr<Server> server(builder.BuildAndStart());
62  std::cout << "127.0.0.1:" << bound_port << std::endl;
63 
64  // Wait for the server to shutdown. Note that some other thread must be
65  // responsible for shutting down the server for this call to ever return.
66  server->Wait();
67 }
68 
69 int main(int argc, char** argv) {
70  RunServer();
71 
72  return 0;
73 }
grpc::ServerContext
Definition: grpcpp/impl/codegen/server_context.h:566
grpc::EnableDefaultHealthCheckService
void EnableDefaultHealthCheckService(bool enable)
Definition: health_check_service.cc:30
proto_server_reflection_plugin.h
benchmark.request
request
Definition: benchmark.py:77
testing::internal::string
::std::string string
Definition: bloaty/third_party/protobuf/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:881
framework.rpc.grpc_channelz.Server
Server
Definition: grpc_channelz.py:42
health_check_service_interface.h
hellostreamingworld_pb2.HelloRequest
HelloRequest
Definition: hellostreamingworld_pb2.py:102
OK
@ OK
Definition: cronet_status.h:43
server_address
std::string server_address("0.0.0.0:10000")
main
int main(int argc, char **argv)
Definition: test/distrib/bazel/cpp/greeter_server.cc:69
server
std::unique_ptr< Server > server
Definition: channelz_service_test.cc:330
profile_analyzer.builder
builder
Definition: profile_analyzer.py:159
GreeterServiceImpl::SayHello
Status SayHello(ServerContext *context, const HelloRequest *request, HelloReply *reply) override
Definition: test/distrib/bazel/cpp/greeter_server.cc:39
grpc::ServerBuilder
A builder class for the creation and startup of grpc::Server instances.
Definition: grpcpp/server_builder.h:86
grpcpp.h
helloworld.Greeter
Definition: helloworld.py:32
GreeterServiceImpl
Definition: grpc-helloworld.cc:39
hellostreamingworld_pb2.HelloReply
HelloReply
Definition: hellostreamingworld_pb2.py:109
RunServer
void RunServer()
Definition: test/distrib/bazel/cpp/greeter_server.cc:47
server
Definition: examples/python/async_streaming/server.py:1
prefix
static const char prefix[]
Definition: head_of_line_blocking.cc:28
grpc::protobuf::util::Status
GRPC_CUSTOM_UTIL_STATUS Status
Definition: include/grpcpp/impl/codegen/config_protobuf.h:93
grpc::Status
Definition: include/grpcpp/impl/codegen/status.h:35
grpc::InsecureServerCredentials
std::shared_ptr< ServerCredentials > InsecureServerCredentials()
Definition: insecure_server_credentials.cc:52
context
grpc::ClientContext context
Definition: istio_echo_server_lib.cc:61
service
__attribute__((deprecated("Please use GRPCProtoMethod."))) @interface ProtoMethod NSString * service
Definition: ProtoMethod.h:25
grpc::reflection::InitProtoReflectionServerBuilderPlugin
void InitProtoReflectionServerBuilderPlugin()
Definition: proto_server_reflection_plugin.cc:66


grpc
Author(s):
autogenerated on Fri May 16 2025 02:58:44