Example #1
0
        public void Tick()
        {
            gateway.Tick();
            uint current = (uint)TimeUtility.GetTotalMillisecondsSince1970();

            if (current - lastClearGameTime > FSPGame.ActiveTimeout * 1000 / 2)
            {
                lastClearGameTime = current;
                ClearNoActiveGame();
            }

            long nowticks = DateTime.Now.Ticks;
            long interval = nowticks - lastTicks;

            long frameIntervalTicks = param.serverFrameInterval * 10000;

            if (interval > frameIntervalTicks)
            {
                lastTicks = nowticks - (nowticks % (frameIntervalTicks));
                if (!useCustomEnterFrame)
                {
                    EnterFrame();
                }
            }
        }
Example #2
0
        public void Tick()
        {
            if (!isRunning)
            {
                return;
            }
            DoReceiveInMain();
            uint current = (uint)TimeUtility.GetTotalMillisecondsSince1970();

            if (needKcpUpdateFlag || current >= nextKcpUpdateTime)
            {
                if (kcp != null)
                {
                    kcp.Update(current);
                    nextKcpUpdateTime = kcp.Check(current);
                    needKcpUpdateFlag = false;
                }
            }
            if (isWaitReconnect)
            {
                if (NetworkInterface.GetIsNetworkAvailable())
                {
                    Reconnect();
                }
                else
                {
                    Debuger.Log("等待重连,但是网络不可用!");
                }
            }
            CheckTimeOut();
        }
Example #3
0
        private void DoReceiveInMain()
        {
            recvBuffQueue.Switch();
            while (!recvBuffQueue.Empty())
            {
                var recvBufferRaw = recvBuffQueue.Pop();
                int ret           = kcp.Input(recvBufferRaw, recvBufferRaw.Length);

                if (ret < 0)
                {
                    Debuger.LogError("收到不正确的KCP包, Ret:{0}", ret);
                    return;
                }

                needKcpUpdateFlag = true;
                for (int size = kcp.PeekSize(); size > 0; size = kcp.PeekSize())
                {
                    var recvBuffer = new byte[size];
                    if (kcp.Recv(recvBuffer) > 0)
                    {
                        lastRecvTimestamp = (uint)TimeUtility.GetTotalMillisecondsSince1970();
                        var data = ProtoBuffUtility.Deserialize <FSPDataSToC>(recvBuffer);
                        recvListener?.Invoke(data.frame);
                    }
                }
            }
        }
Example #4
0
        private void CheckTimeOut()
        {
            uint current = (uint)TimeUtility.GetTotalMillisecondsSince1970();

            if ((current - lastRecvTimestamp) > TimeOut)
            {
                isWaitReconnect = true;
            }
        }
 public void Tick()
 {
     if (Connected)
     {
         DoReceiveInMain();
         uint current = (uint)TimeUtility.GetTotalMillisecondsSince1970();
         if (needKcpUpdateFlag || current >= nextKcpUpdateTime)
         {
             kcp.Update(current);
             nextKcpUpdateTime = kcp.Check(current);
             needKcpUpdateFlag = false;
         }
     }
 }
        public void Tick()
        {
            if (IsRunning)
            {
                lock (mapSession)
                {
                    uint current = (uint)TimeUtility.GetTotalMillisecondsSince1970();

                    if (current - lastClearSessionTime > FSPSession.ActiveTimeout * 1000 / 2)
                    {
                        lastClearSessionTime = current;
                        ClearNoActiveSession();
                    }

                    foreach (KeyValuePair <uint, FSPSession> keyValuePair in mapSession)
                    {
                        keyValuePair.Value.Tick(current);
                    }
                }
            }
        }
Example #7
0
        public void Tick()
        {
            if (isRunning)
            {
                lock (sessions)
                {
                    uint current = (uint)TimeUtility.GetTotalMillisecondsSince1970();
                    if (current - lastClearSessionTime > KCPSession.ActiveTimeout * 1000 / 2)
                    {
                        lastClearSessionTime = current;
                        ClearNoActiveSession();
                    }

                    if (protocolType == enProtocolType.KCP)
                    {
                        foreach (KeyValuePair <uint, ISession> keyValuePair in sessions)
                        {
                            keyValuePair.Value.Tick(current);
                        }
                    }
                }
            }
        }
Example #8
0
 public bool Connect(string ipAddress, int listenPort)
 {
     if (currentSocket != null)
     {
         Debuger.LogError("无法建立连接,需要先关闭上一次连接!");
         return(false);
     }
     ip   = ipAddress;
     port = listenPort;
     lastRecvTimestamp = (uint)TimeUtility.GetTotalMillisecondsSince1970();
     try
     {
         remoteEndPoint = IPUtility.GetHostEndPoint(ip, port);
         if (remoteEndPoint == null)
         {
             Debuger.LogError("无法将Host解析为IP!");
             Close();
             return(false);
         }
         currentSocket = new Socket(remoteEndPoint.AddressFamily, SocketType.Dgram, ProtocolType.Udp);
         currentSocket.Bind(IPUtility.GetIPEndPointAny(AddressFamily.InterNetwork, 0));
         isRunning  = true;
         threadRecv = new Thread(ThreadRecv)
         {
             IsBackground = true
         };
         threadRecv.Start();
     }
     catch (Exception e)
     {
         Debuger.LogError(e.Message + e.StackTrace);
         Close();
         return(false);
     }
     return(true);
 }