问题描述
我们使用嵌入式设备通过串口到以太网转换器将数据包从串行端口发送到服务器。我们使用的一个制造商,Moxa将始终以与构造相同的方式发送数据包。意思是,如果我们构造一个255的数据包,它将始终以255的长度发送数据包。另一个制造商Tibbo,如果我们发送数据包大小为255,那么如果它大于128,它将打破数据包。这是当时从Tibbo工程师收到的答案:
We use an embedded device to send packets from a serial port over a serial-to-Ethernet converter to a server. One manufacturer we use, Moxa, will always send the packets in the same manner which they are constructed. Meaning, if we construct a packet size of 255, it will always send the packet in a 255 length. The other manufacturer, Tibbo, if we send the packet size 255, it will break the packet up if it is greater than 128. This is the answer I received from the Tibbo engineers at the time:
我知道这可能不是如何TCP被设计为使用,但是如果我创建一个255字节的数据包,并且TCP允许它,那么TCP在TCP之外如何工作?我明白,在某些时候,数据包可能会分解,但是如果服务器期望某个数据包的大小,并且Moxa的产品与Tibbo设备没有相同的问题。
I understand that this may not be how TCP was designed to be used, but if I create a packet of 255 bytes and TCP allows it, then how is this outside of how TCP works? I understand that at some point the packet may get broken up but if the server is expecting a certain packet size and Moxa's offering does not have the same problem as the Tibbo device.
那么,是否可以保证合理的TCP数据包大小?
So, is it possible to guarantee a reasonable TCP packet size?
推荐答案
没有。 TCP不是数据包协议,它是一个流协议。它保证您发送的字节将全部到达,并以正确的顺序,但没有别的。特别地,TCP不给你任何类型的消息或分组边界。如果你想要这样的东西,他们需要在你的协议的更高级别上实现。
No. TCP is not a packet protocol, it is a stream protocol. It guarantees that the bytes you send will all arrive, and in the right order, but nothing else. In particular, TCP does not give you any kind of message or packet boundaries. If you want such things, they need to be implemented at a higher level by your protocol.
这篇关于保证TCP包大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!