DatagramPacket contents...

a UDP packet has the data(bytes[]) and data length(int length)
of course there is the problem in that ints over 128(or 255) can’t be a byte. I need to send x,y position and rotation, clientID, etc… the usualstuff.
Can a datagram packet hold data[][]l, in order to send an int converted to a byte array?

How do you guys send locational info to clients?

M

An octet (aka: byte) is the unit of data transfer on ther internet and most other network techonoliges. It’s your job to convert between your data and a series of bytes.

Being that I like NIO I’d do something like:

byte[] data = ...; // from the UDP packet
java.nio.ByteBuffer bb = ByteBuffer.wrap(data);
int x = bb.getInt();
int y = bb.getInt();

Another way would be to wrap the data array in a java.io.ByteArrayInputStream and wrap that in a java.io.DataInputStream and then use the readInt() method.

I think but have no real proof that the NIO method is more efficient but without testing I don’t know.