I am using bidirectional grpc between my client and server. I would like to implement async bidi on both client and server i.e., client opens a stream and starts sending arbitrary messages to server, while another thread continues receiving server responses. This example below demonstrates the server side async bidi https://groups.google.com/forum/m/#!topic/grpc-io/DuBDpK96B14. Has anyone tried async bidi on client side?
Asked
Active
Viewed 3,627 times
1 Answers
-2
There's a codelab for it with both client and server at https://grpc.io/docs/tutorials/async/helloasync-cpp/
Async client
To use an asynchronous client to call a remote method, you first create a channel and stub, just as you do in a synchronous client. Once you have your stub, you do the following to make an asynchronous call:
Initiate the RPC and create a handle for it. Bind the RPC to a CompletionQueue.
CompletionQueue cq;
std::unique_ptr<ClientAsyncResponseReader<HelloReply> > rpc(
stub_->AsyncSayHello(&context, request, &cq));
Ask for the reply and final status, with a unique tag
Status status;
rpc->Finish(&reply, &status, (void*)1);
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.
void* got_tag;
bool ok = false;
cq.Next(&got_tag, &ok);
if (ok && got_tag == (void*)1) {
// check reply and status
}
You can see the complete client example in greeter_async_client.cc.

QOTJ
- 112
- 3
-
Seems to just be a copy from the tutorial web site... – Peter Gaston Feb 20 '21 at 16:03