3 * Copyright 2015 gRPC authors.
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <gflags/gflags.h>
24 #include <grpc/support/log.h>
25 #include <grpcpp/server.h>
26 #include <grpcpp/server_builder.h>
27 #include <grpcpp/server_context.h>
29 #include "src/proto/grpc/testing/echo.grpc.pb.h"
30 #include "test/cpp/util/test_config.h"
32 DEFINE_string(address, "", "Address to bind to");
34 using grpc::testing::EchoRequest;
35 using grpc::testing::EchoResponse;
37 // In some distros, gflags is in the namespace google, and in some others,
38 // in gflags. This hack is enabling us to find both.
41 using namespace google;
42 using namespace gflags;
47 class ServiceImpl final : public ::grpc::testing::EchoTestService::Service {
49 ServerContext* context,
50 ServerReaderWriter<EchoResponse, EchoRequest>* stream) override {
52 EchoResponse response;
53 while (stream->Read(&request)) {
54 gpr_log(GPR_INFO, "recv msg %s", request.message().c_str());
55 response.set_message(request.message());
56 stream->Write(response);
65 ServerBuilder builder;
66 builder.AddListeningPort(FLAGS_address, grpc::InsecureServerCredentials());
67 builder.RegisterService(&service);
68 std::unique_ptr<Server> server(builder.BuildAndStart());
69 std::cout << "Server listening on " << FLAGS_address << std::endl;
72 } // namespace testing
75 int main(int argc, char** argv) {
76 grpc::testing::InitTest(&argc, &argv, true);
77 grpc::testing::RunServer();