DatagramPacket - does Java frag and rearrange it first?

I'm new to the whole UDP thing ('cause everyone loves TCP) and need to ask a few questions about Java's implementation.

I need somebody to tell me whether:

  1. The DatagramPackets sent by Java are fragmented automatically due to network configurations and data size.
  2. The DatagramPackets are rearranged to be in the correct frag sequential order by Java after being fragmented automatically due to network configurations and data size... before the receive() call returns the result.
  3. If fragmented DatagramPackets that're incomplete are dropped or generate Exceptions when dropped. (Some fragments received, others lost)

I'm concerned that Java drops it silently, or data is not arranged correctly... which would mean that I have to implement a pseudo TCP kind of thing to have both the benefits of UDP, as well as the checking of TCP.

Answers


The DatagramPackets sent by Java are fragmented automatically due to network configurations and data size.

Yes, but Java has nothing to do with it.

The DatagramPackets are rearranged to be in the correct frag sequential order by Java after being fragmented automatically due to network configurations and data size... before the receive() call returns the result.

Yes, but not by Java, and only if all the fragments arrive. This happens at the IP layer.

If fragmented DatagramPackets that're incomplete are dropped or generate Exceptions when dropped. (Some fragments received, others lost)

They are dropped silently. No exception. Again Java has nothing to do with it. It all happens at the IP layer. If and only if all the fragments arrive, the datagram is reassembled and passed up to the UDP layer. Java is not involved in any way.

I'm concerned that Java drops it silently

Java does nothing. IP drops it silently.

or data is not arranged correctly

A datagram is received either intact and entire or not at all. Again Java has nothing to do with it.

which would mean that I have to implement a pseudo TCP kind of thing to have both the benefits of UDP, as well as the checking of TCP.

Correct. You do.


UDP is largely implemented in the OS and Java has very little say in the matter.

  • packets over 576 bytes long can be fragmented;
  • packets can be lost;
  • packets can arrive out of order.

There is no way for Java, or you to tell whether these have happened.

What you can do is implement a protocol to detect this. e.g. adding a sequence number, length and checksum to the start of each packet.

which would mean that I have to implement a pseudo TCP kind of thing to have both the benefits of UDP, as well as the checking of TCP.

And now you are starting to understand why "everyone loves TCP" or most people do. UDP has its uses but for most applications TCP is simplest.


Need Your Help

Overwriting custom event handler of as ScrollViewer

c# wpf event-handling scrollviewer

I am trying to overwrite a event handler of MouseWheel for a ScrollViewer. Since ScrollViewer is sealed, I cant simply create a "custom" class inheriting it. I guess the generic question would be: ...

Spring security custom authentication how to access firstname and lastname

java spring spring-mvc spring-security

I am using custom authentication using credentials and ipaddress, however, I need to display user firstname and lastname on UI. Whereas I am not using UserDetails and I am using