I asked the author of the
Java NIO book and here is his reply:
Datagrams are chunky.
There are basically two types of network connections: streams (TCP) and datagrams (UDP). TCP streams (as modeled by SocketChannel objects) function like a pipe where everything blends together into a continuous stream.
Datagrams (as modeled by the DatagramChannel class) are independent chunks. No datagram has any relationship to any other. The metaphor that best applies is letters in a mailbox. Each has a data payload but there is no notion of order or relationship. Datagrams could be sent in the order A, B, C
but arrive at the destination in the order B, C, A.
So, the answer to your question is "no". It's one read per datagram and they will never mix together. One gotcha to think about is that if the ByteBuffer you're reading into is not big enough to hold the entire datagram, the excess data will be silently discarded.
... which is what I wanted to hear.
