Показать сообщение отдельно
Старый 29.02.2012, 13:08   #153
Новичок
 
Регистрация: 17.02.2012
Сообщений: 3
Сказал Спасибо: 2
Имеет 2 спасибок в 1 сообщении
sko пока неопределено
По умолчанию

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;
	}
}
sko вне форума   Ответить с цитированием