/// <summary>
        /// Reads all packets and create messages
        /// </summary>
        protected void BaseHeartbeat(double now)
        {
            // discovery
            NetProfiler.BeginSample("_CheckLocalDiscovery");
            m_discovery.Heartbeat(now);
            NetProfiler.EndSample();

            // Send queued system messages
            NetProfiler.BeginSample("_SendQueuedSystemMessages");
            SendQueuedSystemMessages();
            NetProfiler.EndSample();

            // Send out-of-band messages
            NetProfiler.BeginSample("_SendQueuedUnconnectedMessages");
            SendQueuedOutOfBandMessages();
            NetProfiler.EndSample();

//#if DEBUG
            NetProfiler.BeginSample("_SendLagSimulatedPackets");
            SendDelayedPackets(now);
            NetProfiler.EndSample();
//#endif

            // TODO: move this up in order
            NetProfiler.BeginSample("_ReceivePackets");
            ReceivePackets(now);
            NetProfiler.EndSample();
        }
        internal void Heartbeat(double now)
        {
            if (m_status == NetConnectionStatus.Disconnected)
            {
                return;
            }

            //CongestionHeartbeat(now);

            if (m_status == NetConnectionStatus.Connecting)
            {
                NetProfiler.BeginSample("_CheckHandshake");
                CheckHandshake(now);
                NetProfiler.EndSample();
            }
            else if (m_status == NetConnectionStatus.Connected)
            {
                // send ping?
                NetProfiler.BeginSample("_CheckPing");
                CheckPing(now);
                NetProfiler.EndSample();
            }

            if (m_requestDisconnect)
            {
                NetProfiler.BeginSample("_InitiateDisconnect");
                InitiateDisconnect();
                NetProfiler.EndSample();
            }

            if (now > m_futureClose)
            {
                NetProfiler.BeginSample("_FinalizeDisconnect");
                FinalizeDisconnect();
                NetProfiler.EndSample();
            }

            // Resend all packets that has reached a mature age
            NetProfiler.BeginSample("_ResendMessages");
            ResendMessages(now);
            NetProfiler.EndSample();

            // send all unsent messages
            NetProfiler.BeginSample("_SendOutgoingMessages");
            SendUnsentMessages(now);
            NetProfiler.EndSample();
        }
        /// <summary>
        /// Reads and sends messages from the network
        /// </summary>
        public override void Heartbeat()
        {
            if (!m_isBound)
            {
                return;
            }

            NetProfiler.BeginSample("_GetTime");
            double now = NetTime.Now;

            NetProfiler.EndSample();

            NetProfiler.BeginSample("_UpdateCounter");
            m_heartbeatCounter.Count(now);
            NetProfiler.EndSample();

            // read messages from network
            BaseHeartbeat(now);

            NetProfiler.BeginSample("_UpdateConnections");
            UpdateConnections(now);
            NetProfiler.EndSample();
        }