Merge pull request #151 from yang-g/channel

Sync up channel/server creation changes from grpc/grpc.
pull/3109/head
Nicolas Noble 10 years ago
commit 94b5bf467d
  1. 6
      cpp/cpptutorial.md
  2. 2
      cpp/helloworld/Makefile
  3. 4
      cpp/helloworld/greeter_client.cc
  4. 3
      cpp/helloworld/greeter_server.cc
  5. 2
      cpp/route_guide/Makefile
  6. 4
      cpp/route_guide/route_guide_client.cc
  7. 3
      cpp/route_guide/route_guide_server.cc

@ -214,7 +214,7 @@ void RunServer(const std::string& db_path) {
RouteGuideImpl service(db_path);
ServerBuilder builder;
builder.AddPort(server_address);
builder.AddPort(server_address, grpc::InsecureServerCredentials());
builder.RegisterService(&service);
std::unique_ptr<Server> server(builder.BuildAndStart());
std::cout << "Server listening on " << server_address << std::endl;
@ -239,10 +239,10 @@ In this section, we'll look at creating a C++ client for our `RouteGuide` servic
To call service methods, we first need to create a *stub*.
First we need to create a gRPC *channel* for our stub, specifying the server address and port we want to connect to and any special channel arguments - in our case we'll use the default `ChannelArguments`:
First we need to create a gRPC *channel* for our stub, specifying the server address and port we want to connect to and any special channel arguments - in our case we'll use the default `ChannelArguments` and no SSL:
```cpp
grpc::CreateChannelDeprecated("localhost:50051", ChannelArguments());
grpc::CreateChannel("localhost:50051", grpc::InsecureCredentials(), ChannelArguments());
```
Now we can use the channel to create our stub using the `NewStub` method provided in the `RouteGuide` class we generated from our .proto.

@ -32,7 +32,7 @@
CXX = g++
CPPFLAGS += -I/usr/local/include -pthread
CXXFLAGS += -std=c++11
LDFLAGS += -L/usr/local/lib -lgrpc -lgrpc++ -lprotobuf -lpthread -ldl
LDFLAGS += -L/usr/local/lib -lgrpc++_unsecure -lgrpc -lgpr -lprotobuf -lpthread -ldl
PROTOC = protoc
GRPC_CPP_PLUGIN = grpc_cpp_plugin
GRPC_CPP_PLUGIN_PATH ?= `which $(GRPC_CPP_PLUGIN)`

@ -40,6 +40,7 @@
#include <grpc++/channel_interface.h>
#include <grpc++/client_context.h>
#include <grpc++/create_channel.h>
#include <grpc++/credentials.h>
#include <grpc++/status.h>
#include "helloworld.pb.h"
@ -80,7 +81,8 @@ int main(int argc, char** argv) {
grpc_init();
GreeterClient greeter(
grpc::CreateChannelDeprecated("localhost:50051", ChannelArguments()));
grpc::CreateChannel("localhost:50051", grpc::InsecureCredentials(),
ChannelArguments()));
std::string user("world");
std::string reply = greeter.SayHello(user);
std::cout << "Greeter received: " << reply << std::endl;

@ -39,6 +39,7 @@
#include <grpc++/server.h>
#include <grpc++/server_builder.h>
#include <grpc++/server_context.h>
#include <grpc++/server_credentials.h>
#include <grpc++/status.h>
#include "helloworld.pb.h"
@ -64,7 +65,7 @@ void RunServer() {
GreeterServiceImpl service;
ServerBuilder builder;
builder.AddPort(server_address);
builder.AddPort(server_address, grpc::InsecureServerCredentials());
builder.RegisterService(&service);
std::unique_ptr<Server> server(builder.BuildAndStart());
std::cout << "Server listening on " << server_address << std::endl;

@ -32,7 +32,7 @@
CXX = g++
CPPFLAGS += -I/usr/local/include -pthread
CXXFLAGS += -std=c++11
LDFLAGS += -L/usr/local/lib -lgpr -lgrpc -lgrpc++ -lprotobuf -lpthread -ldl
LDFLAGS += -L/usr/local/lib -lgrpc++_unsecure -lgrpc -lgpr -lprotobuf -lpthread -ldl
PROTOC = protoc
GRPC_CPP_PLUGIN = grpc_cpp_plugin
GRPC_CPP_PLUGIN_PATH ?= `which $(GRPC_CPP_PLUGIN)`

@ -43,6 +43,7 @@
#include <grpc++/channel_interface.h>
#include <grpc++/client_context.h>
#include <grpc++/create_channel.h>
#include <grpc++/credentials.h>
#include <grpc++/status.h>
#include <grpc++/stream.h>
#include "helper.h"
@ -242,7 +243,8 @@ int main(int argc, char** argv) {
// Expect only arg: --db_path=path/to/route_guide_db.json.
std::string db = examples::GetDbFileContent(argc, argv);
RouteGuideClient guide(
grpc::CreateChannelDeprecated("localhost:50051", ChannelArguments()),
grpc::CreateChannel("localhost:50051", grpc::InsecureCredentials(),
ChannelArguments()),
db);
std::cout << "-------------- GetFeature --------------" << std::endl;

@ -42,6 +42,7 @@
#include <grpc++/server.h>
#include <grpc++/server_builder.h>
#include <grpc++/server_context.h>
#include <grpc++/server_credentials.h>
#include <grpc++/status.h>
#include <grpc++/stream.h>
#include "helper.h"
@ -186,7 +187,7 @@ void RunServer(const std::string& db_path) {
RouteGuideImpl service(db_path);
ServerBuilder builder;
builder.AddPort(server_address);
builder.AddPort(server_address, grpc::InsecureServerCredentials());
builder.RegisterService(&service);
std::unique_ptr<Server> server(builder.BuildAndStart());
std::cout << "Server listening on " << server_address << std::endl;

Loading…
Cancel
Save