简体   繁体   中英

Java UDP Server IP Fragmentation

I'm sending a 2000 bytes JSON through Ethernet (Ethernet MTU 1500 bytes), as my packet is greater than the Ethernet MTU, my message it's fragmented as you can see in the Wireshark captures below. Now I'm trying to reassemble this packet in 1 in the destination server, developed in Java.

If I send smaller packets my server is able to receive the data and print it in a command window. But when I send the 2000 bytes packet I don't see anything.

I don't know how to capture both packets and reassemble it in one in Java. I've read that the IP Layer does exactly that but I don't know why is not working properly.

在此处输入图片说明

I don't know how to capture both packets and reassemble it in one in Java.

You can't using standard Java APIs. Either the OS will reassemble the IP packets into UDP datagrams, or the datagrams will be lost. Partial datagrams will not be delivered to your application.

However, I'm not sure how to interpret the Wireshark output. It looks to me like Wireshark is only seeing the first fragment of the fragmented UDP datagrams.

Is it possible that there is an MTU mismatch; eg the sender is sending monster packets?

Is it possible that you haven't told Wireshark to reassemble the packets befor analyzing them? (See https://wiki.wireshark.org/IP_Reassembly )


My advice would be to keep your UDP datagram size smaller than the MTU size. If your messages need to be larger than that, use TCP rather than UDP.

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