简体   繁体   English

Java TCP拆分数据包

[英]Java TCP split packets

I am using spring-integration TCP connections. 我正在使用spring-integration TCP连接。 From the Serializer implementation i write some bytes directly to the given OutputStream. 从Serializer实现中,我直接将一些字节写入给定的OutputStream。

The first byte seems to be sent on its own (in it's own TCP packet, which is by the way reported malformed by wireshark) and then the remaining bytes in the next packet. 第一个字节似乎是自己发送的(在它自己的TCP数据包中,通过wireshark报告格式错误),然后是下一个数据包中的其余字节。

Changing the first two bytes to be written in one call (two byte long array) causes these two bytes to be sent in a seperate packet (not malformed) and the remaning in the next packet. 更改要在一个调用中写入的前两个字节(长为两个字节的数组)会导致这两个字节在一个单独的数据包(未格式错误)中发送,并在下一个数据包中剩余。 This outcome is reproducible. 此结果是可重现的。

Is this something I can (or should) affect? 这是我可以(或应该)影响的事情吗? It is causing problems on the reading end, because that equipment apparently expects the entire message to be contained in a single TCP packet. 这在读取端引起了问题,因为该设备显然希望整个消息包含在单个TCP数据包中。

Is this something I can (or should) affect? 这是我可以(或应该)影响的事情吗? It is causing problems on the reading end, because that equipment apparently expects the entire message to be contained in a single TCP packet. 这在读取端引起了问题,因为该设备显然希望整个消息包含在单个TCP数据包中。

Then the author of this application has no idea of TCP. 因此,该应用程序的作者不了解TCP。 TCP is a stream based and not a packet based protocol. TCP是基于流的协议,而不是基于分组的协议。 This means that a single write can result into multiple packets on the wire or multiple writes can result in a single packet. 这意味着一次写入可能会导致线路上出现多个数据包,或者多次写入可能会导致单个数据包。

...which is by the way reported malformed by wireshark... ...据报道是Wireshark格式不正确的...

If you capture the packets on the sender system you probably see the effects of offloading the checksum computing to the network card. 如果在发件人系统上捕获了数据包,则可能会看到将校验和计算卸载到网卡的效果。 In this case wireshark will report the checksums wrong. 在这种情况下,wireshark将报告错误的校验和。 If you capture the packets in-between or on the receiving end you should see the correct checksum because the network card on the senders machine calculated the checksum before forwarding the packet. 如果您在接收端之间或接收端捕获数据包,则应该看到正确的校验和,因为发送方计算机上的网卡在转发数据包之前已计算了校验和。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM