In my Java application, I get DatagramPacket (s) via DatagramSocket. I know the maximum number of bytes a packet can contain, but in fact each packet length changes (does not exceed the maximum length).
Suppose MAX_PACKET_LENGTH = 1024 (bytes). Therefore, every time a DatagramPacket is received, it has a length of 1024 bytes, but not all bytes always contain information. It may happen that a packet has 10 bytes of payload and the remaining 1014 bytes are filled with 0x00.
I am wondering if there is any elegant way to trim these 0x00 (unused) bytes in order to transfer only useful data to another layer? (maybe some Java built-in methods looping around and analyzing what the package contains are not a desirable solution :))
Thanks for all the tips. Peter
source
share