public static void HandlePacketData(byte[] _data) { byte[] _buffer = (byte[])_data.Clone(); int _packetLength = 0; if (m_Buffer == null) { m_Buffer = new r_ByteBuffer(); } m_Buffer.WriteBytes(_buffer); if (m_Buffer.Count() == 0) { m_Buffer.Clear(); return; } if (m_Buffer.Length() >= 4) { _packetLength = m_Buffer.ReadInteger(false); if (_packetLength <= 0) { m_Buffer.Clear(); return; } } while (_packetLength > 0 & _packetLength <= m_Buffer.Length() - 4) { if (_packetLength <= m_Buffer.Length() - 4) { m_Buffer.ReadInteger(); _data = m_Buffer.ReadBytes(_packetLength); HandlePacket(_data); } _packetLength = 0; if (m_Buffer.Length() >= 4) { _packetLength = m_Buffer.ReadInteger(false); if (_packetLength <= 0) { m_Buffer.Clear(); return; } } } if (_packetLength <= 1) { m_Buffer.Clear(); } }