0
votes

I developing TCP Server Program but I stucked this Server's Protocol the header is fixed by 0xAA55, header size is 2 Byte this is the problem I dont know fill in 0xAA55 to byte array

byte[] tmp = new byte[2]; tmp = 0xAA55;

this is not work..

1

1 Answers

1
votes

You could wrap tmp with a ByteBuffer and then use ByteBuffer.putShort(short) like

byte[] tmp = new byte[2];
ByteBuffer bb = ByteBuffer.wrap(tmp);
bb.putShort((short) 0xAA55);
System.out.println(Arrays.toString(tmp));