GRPC如何实现“双向流rpc”像一个websocket?

发布于 2025-01-18 00:02:31 字数 415 浏览 2 评论 0原文

这个双向流是 http2 原生的吗?我查看了各种http2客户端。我找不到任何允许客户端和服务器建立单个连接并持续从双方推送消息的示例。

(对于http2可能在较低的级别上,客户端/服务器之间的通信只有一个tcp连接,并且所有请求/响应都在其中复用,但从应用程序级别找不到任何建立单个连接对象的示例,并且该连接对象可以重用来相互推送消息)。

那么grpc是如何实现“双向流式RPC”的呢?具体在本文档中 https://grpc.io/docs/what-is-grpc/core -概念/ 它表明服务器端可以定义一个双向流式RPC,它允许客户端和服务器端不断地推送消息,并实现类似websocket的功能。

Is this bidirectional stream native to http2? I looked at various http2 client. I couldn't find any example where it allows the client and server to establish a single connection and continuously push messages from both side.

(For http2 maybe on a lower level, the communications between client/server just had one tcp connection and all the request/responses are multiplexed in it, but from application level can't find any example where you establish a single connection object, and that connection object can be reused to push messages to each other).

So how did grpc achieve "Bidirectional streaming RPCs"? Specifically in this document
https://grpc.io/docs/what-is-grpc/core-concepts/
It indicates that the server side could define a Bidirectional streaming RPC, and it allows both the client and server side to continuously push messages, and achieve features that is websocket like.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

花开半夏魅人心 2025-01-25 00:02:31

是的,双向流是HTTP/2的原生。您可以阅读 rfc-7540 允许您在单个TCP连接上创建多个流,并且每个流都可以彼此独立地在任一方向上发送数据。

我不熟悉那里的所有HTTP/2库,但我知道NGHTTP2将允许在C ++中允许它,而且我认为Java和Go在其标准库中具有HTTP/2实现。

Yes, bidirectional streaming is native to HTTP/2. You can read RFC-7540 for the details of how the protocol works, but basically it allows you to create several streams on a single TCP connection, and each stream can send data in either direction independently of each other.

I'm not familiar with all of the HTTP/2 libraries out there, but I know that nghttp2 will allow this in C++, and I think Java and Go have HTTP/2 implementations in their standard libraries.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文