public void sendPacket(PacketInterface packet) { try { packet.encode(); MemoryStream packetBlock = new MemoryStream(); Int32 packetLen = sizeof(Int32) + (Int32)packet.getStream().Length; Byte[] packetHeader = BitConverter.GetBytes(packetLen); PacketObfuscation.encodingHeader(ref packetHeader, (int)packetHeader.Length); packetBlock.Write(packetHeader, 0, (Int32)packetHeader.Length); Byte[] packetData = packet.getStream().ToArray(); PacketObfuscation.encodingData(ref packetData, (int)packetData.Length); packetBlock.Write(packetData, 0, (Int32)packetData.Length); Byte[] packetBytes = packetBlock.ToArray(); stream_.Write(packetBytes, 0, (int)packetBlock.Length); stream_.Flush(); packetBlock = null; } catch (Exception e) { if (this.isConnected()) { MessageBox.Show("잘못된 처리 : " + e.ToString(), "error", MessageBoxButtons.OK); Application.Exit(); } } }
public void receive() { if (stream_.DataAvailable) { Byte[] packetByte = new Byte[client_.ReceiveBufferSize]; Int32 offset = 0; Int32 readLen = stream_.Read(packetByte, offset, packetByte.Length); PacketObfuscation.decodingHeader(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.decodingData(ref packetData, packetData.Length); Packetinterface rowPacket = PacketUtil.packetAnalyzer(packetData); if (rowPacket == null && this.isConnected()) { Debug.Log("잘못된 패킷이 수신되었습니다."); } ContentsProcee_.run(rowPacket); } }
public void receive() { try { while (this.isConnected()) { Byte[] packetByte = new Byte[client_.ReceiveBufferSize]; Int32 offset = 0; Int32 readLen = stream_.Read(packetByte, offset, packetByte.Length); // 패킷 난독화 PacketObfuscation.decodingHeader(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.decodingData(ref packetData, packetData.Length); PacketInterface rowPacket = PacketUtil.packetAnalyzer(packetData); if (rowPacket == null && this.isConnected()) { //MessageBox.Show("잘못된 패킷이 수신되었습니다", "error", MessageBoxButtons.OK); //Application.Exit(); } packetProcee_.run(rowPacket); } this.close(); } catch (Exception e) { if (this.isConnected()) { //MessageBox.Show("잘못된 처리 : " + e.ToString(), "error", MessageBoxButtons.OK); //Application.Exit(); } } }
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(); } } }
public void sendPacket(Packetinterface packet) { try { packet.encode(); //Header -> data 순으로 바이트변환후 packet내 외부스트림에 저장 MemoryStream packetBlock = new MemoryStream(); Int32 packetLen = sizeof(Int32) + (Int32)packet.getStream().Length; Byte[] packetHeader = BitConverter.GetBytes(packetLen); //packetHeader는 Packet의 총길이 PacketObfuscation.encodingHeader(ref packetHeader, (int)packetHeader.Length); //길이 암호화 packetBlock.Write(packetHeader, 0, (Int32)packetHeader.Length); Byte[] packetData = packet.getStream().ToArray(); PacketObfuscation.encodingData(ref packetData, (int)packetData.Length); packetBlock.Write(packetData, 0, (Int32)packetData.Length); //실데이터 암호화후 블럭에 넣음 Byte[] packetBytes = packetBlock.ToArray(); // 블럭을 바이트로 변환 stream_.Write(packetBytes, 0, (int)packetBlock.Length); stream_.Flush(); packetBlock = null; }catch (Exception e) { if (this.isConnected()) { Debug.Log("잘못된 처리 : send " + e.ToString()); } } }