Replicate C++ docs from master to beta branch
Original PR #3074 by @dgquintas
diff --git a/examples/cpp/helloworld/greeter_client.cc b/examples/cpp/helloworld/greeter_client.cc
index bfb7c12..6cd8353 100644
--- a/examples/cpp/helloworld/greeter_client.cc
+++ b/examples/cpp/helloworld/greeter_client.cc
@@ -35,11 +35,8 @@
#include <memory>
#include <string>
-#include <grpc/grpc.h>
-#include <grpc++/channel.h>
-#include <grpc++/client_context.h>
-#include <grpc++/create_channel.h>
-#include <grpc++/security/credentials.h>
+#include <grpc++/grpc++.h>
+
#include "helloworld.grpc.pb.h"
using grpc::Channel;
@@ -54,17 +51,28 @@
GreeterClient(std::shared_ptr<Channel> channel)
: stub_(Greeter::NewStub(channel)) {}
+ // Assambles the client's payload, sends it and presents the response back
+ // from the server.
std::string SayHello(const std::string& user) {
+ // Data we are sending to the server.
HelloRequest request;
request.set_name(user);
+
+ // Container for the data we expect from the server.
HelloReply reply;
+
+ // Context for the client. It could be used to convey extra information to
+ // the server and/or tweak certain RPC behaviors.
ClientContext context;
+ // The actual RPC.
Status status = stub_->SayHello(&context, request, &reply);
+
+ // Act upon its status.
if (status.ok()) {
return reply.message();
} else {
- return "Rpc failed";
+ return "RPC failed";
}
}
@@ -73,6 +81,10 @@
};
int main(int argc, char** argv) {
+ // Instantiate the client. It requires a channel, out of which the actual RPCs
+ // are created. This channel models a connection to an endpoint (in this case,
+ // localhost at port 50051). We indicate that the channel isn't authenticated
+ // (use of InsecureCredentials()).
GreeterClient greeter(
grpc::CreateChannel("localhost:50051", grpc::InsecureCredentials()));
std::string user("world");