blob: 9568ca26be70b026ad265650d491c8d4275f7887 [file] [log] [blame]
Craig Tillerfbac5f12015-05-15 14:20:44 -07001/*
2 *
3 * Copyright 2015, Google Inc.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met:
9 *
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above
13 * copyright notice, this list of conditions and the following disclaimer
14 * in the documentation and/or other materials provided with the
15 * distribution.
16 * * Neither the name of Google Inc. nor the names of its
17 * contributors may be used to endorse or promote products derived from
18 * this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 *
32 */
33
Sree Kuchibhotla5a05f512016-01-13 22:43:20 -080034#include <gflags/gflags.h>
Craig Tillerfbac5f12015-05-15 14:20:44 -070035#include <iostream>
36#include <memory>
37#include <string>
Craig Tillerfbac5f12015-05-15 14:20:44 -070038
39#include <grpc++/server.h>
40#include <grpc++/server_builder.h>
41#include <grpc++/server_context.h>
Craig Tiller1b4e3302015-12-17 16:35:00 -080042#include "src/proto/grpc/testing/echo.grpc.pb.h"
Craig Tillerfbac5f12015-05-15 14:20:44 -070043
44DEFINE_string(address, "", "Address to bind to");
45
Craig Tiller1b4e3302015-12-17 16:35:00 -080046using grpc::testing::EchoRequest;
47using grpc::testing::EchoResponse;
Craig Tillerfbac5f12015-05-15 14:20:44 -070048
49// In some distros, gflags is in the namespace google, and in some others,
50// in gflags. This hack is enabling us to find both.
51namespace google {}
52namespace gflags {}
53using namespace google;
54using namespace gflags;
55
56namespace grpc {
57namespace testing {
58
Sree Kuchibhotla5a05f512016-01-13 22:43:20 -080059class ServiceImpl GRPC_FINAL
60 : public ::grpc::testing::EchoTestService::Service {
Craig Tillerfbac5f12015-05-15 14:20:44 -070061 Status BidiStream(ServerContext* context,
62 ServerReaderWriter<EchoResponse, EchoRequest>* stream)
63 GRPC_OVERRIDE {
64 EchoRequest request;
65 EchoResponse response;
66 while (stream->Read(&request)) {
67 gpr_log(GPR_INFO, "recv msg %s", request.message().c_str());
68 response.set_message(request.message());
69 stream->Write(response);
70 }
71 return Status::OK;
72 }
73};
74
75void RunServer() {
76 ServiceImpl service;
77
78 ServerBuilder builder;
79 builder.AddListeningPort(FLAGS_address, grpc::InsecureServerCredentials());
80 builder.RegisterService(&service);
81 std::unique_ptr<Server> server(builder.BuildAndStart());
82 std::cout << "Server listening on " << FLAGS_address << std::endl;
83 server->Wait();
84}
Craig Tillerfbac5f12015-05-15 14:20:44 -070085}
86}
87
88int main(int argc, char** argv) {
89 ParseCommandLineFlags(&argc, &argv, true);
90 grpc::testing::RunServer();
91
92 return 0;
93}