Exemplo n.º 1
0
 /// <summary>
 /// 更新ack队列
 /// </summary>
 /// <param name="packet"></param>
 public void UpdateAckQueue(PacketSt packet)
 {
     if (AckQueueBuffer.TryRemove(packet.Una - 1, out QueueItem item))
     {
         //说明ack数据包有效,开始处理确认队列
         List <uint> keys = AckQueueBuffer.Keys.Where(t => t < packet.Una).ToList();
         foreach (uint key in keys)
         {
             if (AckQueueBuffer.TryGetValue(key, out QueueItem ackItem))
             {
                 //判断是否需要重新发包
                 if (ackItem.TimeoutNum > TimeOutCount)
                 {
                     //判断是否超过重发包次数
                     if (ackItem.ReSendCount < ReSendCount)
                     {
                         //开始重新发包
                         SendPacket(ackItem.Data);
                         ackItem.ReSendCount++;
                     }
                     //重新计数
                     ackItem.TimeoutNum = 0;
                 }
                 else
                 {
                     ackItem.TimeoutNum++;
                 }
             }
         }
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// 处理数据包
        /// </summary>
        /// <param name="packet"></param>
        /// <returns></returns>
        public bool ExcuteCmd(PacketSt packet)
        {
            bool ret = false;

            switch (packet.Cmd)
            {
            case GlobalConst.IKCP_CMD_ACK:
            {
                UpdateAckQueue(packet);
                ret = true;
                break;
            }

            case GlobalConst.IKCP_CMD_PUSH:
            {
                ret = true;
                //todo:接收数据,并发送确认包
                break;
            }

            case GlobalConst.IKCP_CMD_WASK:
            {
                ret = true;
                //todo:直接调用方法发送数据
                break;
            }

            case GlobalConst.IKCP_CMD_WINS:
            {
                ret = true;
                //todo:直接调用方法发送数据
                break;
            }
            }
            return(ret);
        }