doucong6884 2018-10-16 18:30
浏览 753

gRPC客户端流

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++.

  • 写回答

1条回答 默认 最新

  • duanfazhun0383 2018-10-22 18:53
    关注

    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.

    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!