Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ByteBuffer vs. Buffer on Datagram Packets

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.


1 Answers

A DatagramSocket cannot read directly into a ByteBuffer, but you can do this using a DatagramChannel instead.

like image 121
finnw Avatar answered Oct 28 '25 17:10

finnw