
Originally Posted by
DominicGunn
y read 3 bytes wen onli 1 needed to check policy

also i have a feeling the above snippet will fail at reading messages properly if the client sends multiple msg ids in one packet
you need read 4 bytes (int32) the policy send something like <policy... so you get a big int if try parse.. or checking the first byte "<" (i do this..)
my actual code for parse is..
PHP Code:
private List<byte[]> readIncomingMessage(SocketChannel key, ByteBuffer readBuffer) throws Exception
{
List<byte[]> result = new ArrayList<byte[]>();
Crypto crypto = ...;
byte[] msg;
do
{
msg = readMessage(key, readBuffer, crypto);
if(msg != null)
result.add(msg);
else
break;
}
while (true);
return result;
}
private byte[] readMessage(SocketChannel key, ByteBuffer readBuffer, Crypto crypto)
{
int bytesToRead;
if (readBuffer.remaining()>4)
{
byte[] lengthBytes = new byte[4];
readBuffer.get(lengthBytes);
if(crypto != null)
{
crypto.parse(lengthBytes);
}
bytesToRead = ByteMessage.Int32(lengthBytes, 0);
if (readBuffer.remaining()>=bytesToRead)
{
byte[] resultMessage = new byte[bytesToRead];
readBuffer.get(resultMessage);
if(crypto != null)
{
crypto.parse(resultMessage);
}
// remove message
int remaining = readBuffer.remaining();
System.arraycopy(readBuffer.array(), readBuffer.position(), readBuffer.array(), 0, remaining);
readBuffer.clear().limit(remaining).position(0);
return resultMessage;
}
if(crypto == null && lengthBytes[0] == 60)
{
readBuffer.clear();
write(key, crossdomain, true);
return null;
}
readBuffer.position(0);
}
return null;
}
so i have a List<byte[]> with the packets separated >P