예제 #1
0
 /// <summary>
 /// 处理包
 /// </summary>
 private void ProcessPacket()
 {
     try
     {
         for (; true;)
         {
             PacketBase head = Packing.GetPacketHead(this.m_cReceiveBuffer.m_lstBuffer, this.m_cReceiveBuffer.ReadIndex, this.m_cReceiveBuffer.WriteIndex);
             if (head != null)
             {
                 byte[] buffer = this.m_cReceiveBuffer.Read(head.m_usPacketSize);
                 buffer = Packing.PackingDecode(buffer, head.m_usPacketSize);
                 if (buffer != null)
                 {
                     //MemoryStream ms = new MemoryStream(buffer);
                     //BinaryFormatter bf = new BinaryFormatter();
                     //PacketBase pb = (PacketBase)bf.Deserialize(ms);
                     PacketBase   pb = PacketFactoryManager.GetInstance().CreatePacket(head.GetPacketID());
                     StreamBuffer sb = new StreamBuffer();
                     sb.Init(buffer, buffer.Length);
                     pb.Load(sb);
                     this.m_cDispatch.AckPacket(pb);
                 }
                 else
                 {
                     break;
                 }
             }
             else
             {
                 break;
             }
         }
     }
     catch (Exception e)
     {
         WriteFiles.WritFile.Log(LogerType.ERROR, e.ToString());
         DisConnect();
     }
 }