如何知道数据的总大小?

发布于 2025-01-19 04:36:14 字数 197 浏览 2 评论 0原文

我正在使用 libevent 创建一个小型 p2p 网络。

假设我想从一个节点发送 10,000 字节缓冲区到另一个节点,由于 libevent 一次可以发送的最大大小是 4,096 字节(所以 4,096 + 4,096 + 1,808)。

从技术上讲,接收数据的节点是否可以(在 TCP 协议中)知道接收到前 4,096 个字节时将发送的字节总数?

I'm using libevent for creating a small p2p network.

Let's say that I want to send 10,000 bytes buffer from one node to another, due to libevent the max size that can be send in one time is 4,096 bytes (so 4,096 + 4,096 + 1,808).

Is it technically possible (in TCP protocol) for the node that receives the data, to know the total number of bytes that will be sent when receives the first 4,096 bytes ?

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

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

发布评论

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

评论(1

随心而道 2025-01-26 04:36:14

不会。但是,应用程序协议通常会告诉接收方需要多少字节。对于 HTTP 1.1,它是 Content-Length 标头。您还可以按照 的方式使用长度前缀。 PostgresSQL 在前端和后端之间使用该协议。

No. It is, however, common for the application protocol to tell the receiver how many bytes to expect. With HTTP 1.1, it's the Content-Length header. You can also use length prefix along the lines of <len><data>. PostgresSQL uses that protocol between the front and backend.

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