public override void OnRefresh()
 {
     if (!Available)
     {
         return;
     }
     OnReceive();
     peer.OnRefresh();
     if (awaitHandle.Count > 0)
     {
         UdpReceiveResult data;
         if (awaitHandle.TryDequeue(out data))
         {
             UdpNetworkMessage netMsg = Facade.SpawnReference <UdpNetworkMessage>();
             netMsg.CacheDecodeBuffer(data.Buffer);
             if (Conv == 0)
             {
                 Conv      = netMsg.Conv;
                 peer.Conv = Conv;
                 peer.AllocateConv(Conv);
             }
             if (netMsg.IsFull)
             {
                 peer.MessageHandler(netMsg);
             }
         }
     }
 }
Exemple #2
0
        public static UdpNetworkMessage ConvertToACK(UdpNetworkMessage srcMsg)
        {
            UdpNetworkMessage ack = GameManager.ReferencePoolManager.Spawn <UdpNetworkMessage>();

            ack.Conv          = srcMsg.Conv;
            ack.Snd_una       = srcMsg.Snd_una;
            ack.SN            = srcMsg.SN;
            ack.Cmd           = KcpProtocol.ACK;
            ack.OperationCode = srcMsg.OperationCode;
            ack.EncodeMessage();
            return(ack);
        }
        public override void SendMessage(INetworkMessage netMsg)
        {
            if (!Available)
            {
                return;
            }
            UdpNetworkMessage udpNetMsg = netMsg as UdpNetworkMessage;
            var result = peer.EncodeMessage(ref udpNetMsg);

            if (result)
            {
                SendMessage(udpNetMsg, serverEndPoint);
            }
            else
            {
                Utility.Debug.LogError("INetworkMessage 消息编码失败");
            }
        }
Exemple #4
0
        public void OnRefresh()
        {
            if (!Available)
            {
                return;
            }
            long now = Utility.Time.SecondNow();

            if (now <= LatestHeartbeatTime)
            {
                return;
            }
            LatestHeartbeatTime = now + HeartbeatInterval;
            currentRecurCount  += 1;
            if (currentRecurCount >= MaxRecurCount)
            {
                Available = false;
                UnavailableHandler?.Invoke();
                return;
            }
            SendHeartbeatHandler?.Invoke(UdpNetworkMessage.HeartbeatMessage(Conv));
            Utility.Debug.LogInfo($"客户端发起心跳:Conv : {Conv} ; currentRecurCount : {currentRecurCount}", MessageColor.ORANGE);
        }
        void SendFINMessage()
        {
            UdpNetworkMessage udpNetMsg = new UdpNetworkMessage(0, KcpProtocol.FIN);

            SendMessage(udpNetMsg);
        }
        public override byte[] EncodingMessage(INetworkMessage message)
        {
            UdpNetworkMessage udpNetMsg = message as UdpNetworkMessage;

            return(udpNetMsg.EncodeMessage());
        }