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()); } } }
public void sendPacket(Packetinterface packet) { //Debug.Log("Send Packet : " + packet.GetType().ToString()); 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의 총길이 packetBlock.Write(packetHeader, 0, (Int32)packetHeader.Length); Byte[] packetData = packet.getStream().ToArray(); packetBlock.Write(packetData, 0, (Int32)packetData.Length); Byte[] packetBytes = packetBlock.ToArray(); // 블럭을 바이트로 변환 //Debug.Log("Send Size : " + packetBytes.Length.ToString()); socket.Send(packetBytes); // stream_.Write(packetBytes,0, (int)packetBlock.Length); // stream_.Flush(); packetBlock = null; }catch (Exception e) { if (this.isConnected()) { Debug.Log("잘못된 처리 : send " + e.ToString()); } } }