I need to send a Network Order short for a game server I\'m writing using Java. I read about network order, but I couldn\'t find any details about a short that is sent befor
Java NIO bytes buffers have support for changing the byte order. Network byte order is Big Endian therefore.
// Allocate a big endian byte buffer
ByteBuffer bb = ByteBuffer.allocate(4096);
bb.order(ByteOrder.BIG_ENDIAN);
bb.putShort(12345);
// Write the buffer to an NIO channel
bb.flip();
channel.write(bb);
Byte Order is the order in which the bytes for numerical values that are larger than a single byte are stored. There are 2 flavours Big Endian (most significant byte first) and Little Endian (least significant byte first).