Beispiel #1
0
        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("잘못된 패킷이 수신되었습니다");
                }

                packetProcee_.run(rowPacket);
            }
        }
Beispiel #2
0
 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())
         {
             Debug.Log("잘못된 처리 : send " + e.ToString());
         }
     }
 }