Aries, спасибо за дополнение. Вот
тут есть пример разбора входящего потока на пакеты.
Код:
while (true){
lengthLo = _in.read();
lengthHi = _in.read();
length = lengthHi * 256 + lengthLo;
if (lengthHi < 0)
{
_log.finer("LoginServerThread: Login terminated the connection.");
break;
}
byte[] incoming = new byte[length];
incoming[0] = (byte) lengthLo;
incoming[1] = (byte) lengthHi;
int receivedBytes = 0;
int newBytes = 0;
while (newBytes != -1 && receivedBytes < length - 2)
{
newBytes = _in.read(incoming, 2, length - 2);
receivedBytes = receivedBytes + newBytes;
}
if (receivedBytes != length - 2)
{
_log.warning("Incomplete Packet is sent to the server, closing connection.(LS)");
break;
}
}