예제 #1
0
        /// <summary>
        /// Read messages from network and sends unsent messages, resends etc
        /// This method should be called as often as possible
        /// </summary>
        public void Heartbeat()
        {
            double now = NetTime.Now;

            NetBase.CurrentContext = this;

            // read all packets
            while (ReadPacket())
            {
                ;
            }

            // connection heartbeats
            for (int i = 0; i < Connections.Length; i++)
            {
                NetConnection connection = Connections[i];
                if (connection != null)
                {
                    NetConnectionStatus status = connection.Status;
                    if (status == NetConnectionStatus.Connected || status == NetConnectionStatus.Connecting || status == NetConnectionStatus.Reconnecting)
                    {
                        connection.Heartbeat(now);
                    }
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Reads messages from network and sends unsent messages, resends etc
        /// This method should be called as often as possible; maximum number
        /// of seconds to spend can be specified
        /// </summary>
        public void Heartbeat(float maxSeconds)
        {
            NetBase.CurrentContext = this;

            double now = NetTime.Now;

            base.Heartbeat(now);

            // read packets until out of time (or packets)
            double exit = now + maxSeconds;

            while (ReadPacket())
            {
                if (NetTime.Now > exit)
                {
                    break;
                }
            }

            if (m_serverConnection != null && m_serverConnection.Status != NetConnectionStatus.Disconnected)
            {
                m_serverConnection.Heartbeat(now);
            }
        }