private void InitiateDisconnect()
        {
            if (m_requestSendGoodbye)
            {
                //just do this without regard for other packet and overwrite it
                var scratch = m_owner.GetTempBuffer();
                scratch.Write(string.IsNullOrEmpty(m_futureDisconnectReason) ? "" : m_futureDisconnectReason);
                m_owner.SendSingleUnreliableSystemMessage(
                    NetSystemType.Disconnect,
                    scratch,
                    m_remoteEndPoint,
                    null
                    );
            }

            if (m_requestLinger <= 0)
            {
                FinalizeDisconnect();
                m_futureClose = double.MaxValue;
            }
            else
            {
                SetStatus(NetConnectionStatus.Disconnecting, m_futureDisconnectReason);
                m_futureClose = NetTime.Now + m_requestLinger;
            }

            m_requestDisconnect = false;
        }
        private void InitiateDisconnect()
        {
            if (m_requestSendGoodbye)
            {
                NetBuffer scratch = m_owner.m_scratchBuffer;
                scratch.Reset();
                scratch.Write(string.IsNullOrEmpty(m_futureDisconnectReason) ? "" : m_futureDisconnectReason);
                m_owner.SendSingleUnreliableSystemMessage(
                    NetSystemType.Disconnect,
                    scratch,
                    m_remoteEndPoint,
                    false
                    );
            }

            if (m_requestLinger <= 0)
            {
                SetStatus(NetConnectionStatus.Disconnected, m_futureDisconnectReason);
                FinalizeDisconnect();
                m_futureClose = double.MaxValue;
            }
            else
            {
                SetStatus(NetConnectionStatus.Disconnecting, m_futureDisconnectReason);
                m_futureClose = NetTime.Now + m_requestLinger;
            }

            m_requestDisconnect = false;
        }
 internal static void SendPing(NetBase netBase, IPEndPoint toEndPoint, double now)
 {
     ushort nowEnc = NetTime.Encoded(now);
     NetBuffer buffer = netBase.m_scratchBuffer;
     buffer.Reset();
     buffer.Write(nowEnc);
     netBase.SendSingleUnreliableSystemMessage(
         NetSystemType.Ping,
         buffer,
         toEndPoint,
         false
     );
 }
        internal static void SendPing(NetBase netBase, IPEndPoint toEndPoint, double now)
        {
            ushort    nowEnc = NetTime.Encoded(now);
            NetBuffer buffer = netBase.m_scratchBuffer;

            buffer.Reset();
            buffer.Write(nowEnc);
            netBase.SendSingleUnreliableSystemMessage(
                NetSystemType.Ping,
                buffer,
                toEndPoint,
                false
                );
        }
        /// <summary>
        /// Handle a discovery request
        /// </summary>
        internal void HandleRequest(IncomingNetMessage message, NetworkEndPoint senderEndpoint)
        {
            ushort number;

            if (!VerifyIdentifiers(message, senderEndpoint, out number))
            {
                return;                 // bad app ident or self discovery
            }
            NetBuffer buf = m_netBase.CreateBuffer(2);

            buf.Write(number);

            m_netBase.LogWrite("Sending discovery response to " + senderEndpoint + " request " + number);

            // send discovery response
            m_netBase.SendSingleUnreliableSystemMessage(
                NetSystemType.DiscoveryResponse,
                buf,
                senderEndpoint,
                null
                );

            m_netBase.RecycleBuffer(buf);
        }