public void Receive() { try { while (IsConnected()) { byte[] packetByte = new byte[_Client.ReceiveBufferSize]; Int32 offset = 0; Int32 readLen = _Stream.Read(packetByte, 0, packetByte.Length); PacketObfuscation.DecodeHeader(ref packetByte, sizeof(Int32)); Int32 packetLen = PacketUtil.DecodePacketLen(packetByte, ref offset); while (readLen < packetLen) { byte[] remainPacket = new byte[_Client.ReceiveBufferSize]; Int32 remainLen = 0; remainLen = _Stream.Read(remainPacket, 0, remainPacket.Length); Buffer.BlockCopy(remainPacket, 0, packetByte, readLen, remainLen); readLen += remainLen; } Byte[] packetData = new Byte[_Client.ReceiveBufferSize]; Buffer.BlockCopy(packetByte, offset, packetData, 0, readLen - offset); PacketObfuscation.DecodeData(ref packetData, packetData.Length); IPacket rowPacket = PacketUtil.PacketAnalyzer(packetData); //IPacket rowPacket = PacketUtil.PacketAnalyzer(packetByte, ref offset, readLen); if (rowPacket == null && IsConnected()) { MessageBox.Show("잘못된 패킷이 수신됐습니다", "error", MessageBoxButtons.OK); Application.Exit(); } _PacketProcess.Run(rowPacket); } Close(); } catch (Exception e) { if (IsConnected()) { MessageBox.Show("잘못된 처리:" + e.ToString(), "error", MessageBoxButtons.OK); Application.Exit(); } } }