I've read that ByteBuffer (java.nio) should be used over the Buffer class for reading in data simply because it's more efficient (?). My question revolves around a UDP client that reads packets from a multicast address and processes them into primitive objects. What is the most efficient/fastest way to parse these packets from a DatagramSocket? Right now, I have a datagram packet whose byte array I wrap a ByteBuffer around and read from there. My goal is to minimize new object creation and maximize speed.
A DatagramSocket cannot read directly into a ByteBuffer, but you can do this using a DatagramChannel instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With