如何知道数据的总大小?
我正在使用 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不会。但是,应用程序协议通常会告诉接收方需要多少字节。对于 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.