Marcin Spiewak
Marcin Spiewak

Reputation: 11

gRPC client streaming

Official gRPC documentation for client streaming states that:

The server sends back a single response, typically but not necessarily after it has received all the client’s requests...

What I'm trying to do is to catch server response in the middle of the stream to stop sending more data.

In Go I can spin up a new goroutine listening for the message from the server using RecvMsg, but I can't find a way to do the same in C++. It looks like ClientWriter doesn't offer this kind of functionality.

One solution would be to have a bidirectional stream but was wondering if there is any other way to achieve this in C++.

Upvotes: 1

Views: 2684

Answers (1)

Abhishek Kumar
Abhishek Kumar

Reputation: 11

Once the response and status are sent by the server and received back at the client(i.e., the client-side gRPC stack) , subsequent attempts to Write() will start failing. The first failing Write() is the signal to the client that it should stop Writing and Finish the RPC.

So the two options here are: 1. Wait for a Write to fail, then call finish to receive the Server's response and status. 2. Switch to Bidirectional Streaming if the client really wants to read the response from the server before calling Finish.

Upvotes: 1

Related Questions