I am trying to find the value of the first 2 bytes in a UDP packet which corresponds to the length of the remaining payload. What is the best method to find this value in Java given that I know the first 2 bytes? Would java.nio.ByteBuffer be of any use?
Thanks
I usually use something like this:
Then you take first two bytes of your
DatagramPacket:Mind that I used length as an
intbecause alsoshortdata type (as everyone) is signed in Java, so you need a larger space.