简体   繁体   中英

Java TCP split packets

I am using spring-integration TCP connections. From the Serializer implementation i write some bytes directly to the given 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.

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.

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.

Then the author of this application has no idea of TCP. TCP is a stream based and not a packet based protocol. 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...

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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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