Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
Grpc
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
tci-gateway-module
Grpc
Commits
2e9ce91e
Commit
2e9ce91e
authored
9 years ago
by
James Eady
Committed by
James Eady
9 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Use code type highlight for the code blocks in the cpp helloworld
example README.md ..
parent
5c8c3e78
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
examples/cpp/helloworld/README.md
+14
-14
14 additions, 14 deletions
examples/cpp/helloworld/README.md
with
14 additions
and
14 deletions
examples/cpp/helloworld/README.md
+
14
−
14
View file @
2e9ce91e
...
...
@@ -41,7 +41,7 @@ message from the remote client containing the user's name, then send back
a greeting in a single
`HelloReply`
. This is the simplest type of RPC you
can specify in gRPC - we'll look at some other types later in this document.
```
```
protobuf
syntax
=
"proto3"
;
option
java_package
=
"ex.grpc"
;
...
...
@@ -93,20 +93,20 @@ $ protoc -I ../../protos/ --cpp_out=. ../../protos/helloworld.proto
channel can be created with the target address, credentials to use and
arguments as follows
```
```
cpp
auto channel = CreateChannel("localhost:50051", InsecureChannelCredentials());
```
-
Create a stub. A stub implements the rpc methods of a service and in the
generated code, a method is provided to created a stub with a channel:
```
```
cpp
auto stub = helloworld::Greeter::NewStub(channel);
```
-
Make a unary rpc, with
`ClientContext`
and request/response proto messages.
```
```
cpp
ClientContext context;
HelloRequest request;
request.set_name("hello");
...
...
@@ -116,7 +116,7 @@ $ protoc -I ../../protos/ --cpp_out=. ../../protos/helloworld.proto
-
Check returned status and response.
```
```
cpp
if (status.ok()) {
// check reply.message()
} else {
...
...
@@ -130,7 +130,7 @@ For a working example, refer to [greeter_client.cc](greeter_client.cc).
-
Implement the service interface
```
```
cpp
class GreeterServiceImpl final : public Greeter::Service {
Status SayHello(ServerContext* context, const HelloRequest* request,
HelloReply* reply) override {
...
...
@@ -144,7 +144,7 @@ For a working example, refer to [greeter_client.cc](greeter_client.cc).
-
Build a server exporting the service
```
```
cpp
GreeterServiceImpl service;
ServerBuilder builder;
builder.AddListeningPort("0.0.0.0:50051", grpc::InsecureServerCredentials());
...
...
@@ -170,14 +170,14 @@ The channel and stub creation code is the same as the sync client.
-
Initiate the rpc and create a handle for the rpc. Bind the rpc to a
`CompletionQueue`
.
```
```
cpp
CompletionQueue cq;
auto rpc = stub->AsyncSayHello(&context, request, &cq);
```
-
Ask for reply and final status, with a unique tag
```
```
cpp
Status status;
rpc->Finish(&reply, &status, (void*)1);
```
...
...
@@ -185,7 +185,7 @@ The channel and stub creation code is the same as the sync client.
-
Wait for the completion queue to return the next tag. The reply and status are
ready once the tag passed into the corresponding
`Finish()`
call is returned.
```
```
cpp
void* got_tag;
bool ok = false;
cq.Next(&got_tag, &ok);
...
...
@@ -203,7 +203,7 @@ completion queue to return the tag. The basic flow is
-
Build a server exporting the async service
```
```
cpp
helloworld::Greeter::AsyncService service;
ServerBuilder builder;
builder.AddListeningPort("0.0.0.0:50051", InsecureServerCredentials());
...
...
@@ -214,7 +214,7 @@ completion queue to return the tag. The basic flow is
-
Request one rpc
```
```
cpp
ServerContext context;
HelloRequest request;
ServerAsyncResponseWriter<HelloReply> responder;
...
...
@@ -224,7 +224,7 @@ completion queue to return the tag. The basic flow is
-
Wait for the completion queue to return the tag. The context, request and
responder are ready once the tag is retrieved.
```
```
cpp
HelloReply reply;
Status status;
void* got_tag;
...
...
@@ -239,7 +239,7 @@ completion queue to return the tag. The basic flow is
-
Wait for the completion queue to return the tag. The rpc is finished when the
tag is back.
```
```
cpp
void* got_tag;
bool ok = false;
cq.Next(&got_tag, &ok);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment