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.

    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度