Lidgren.Network.NetConnection.SetStatus C# (CSharp) Method

SetStatus() private method

private SetStatus ( NetConnectionStatus status, string reason ) : void
status NetConnectionStatus
reason string
return void
        internal void SetStatus(NetConnectionStatus status, string reason)
        {
            // user or library thread

            if (status == m_status)
                return;

            m_status = status;
            if (reason == null)
                reason = string.Empty;

            if (m_status == NetConnectionStatus.Connected)
            {
                m_timeoutDeadline = (float)NetTime.Now + m_peerConfiguration.m_connectionTimeout;
                m_peer.LogVerbose("Timeout deadline initialized to  " + m_timeoutDeadline);
            }

            if (m_peerConfiguration.IsMessageTypeEnabled(NetIncomingMessageType.StatusChanged))
            {
                NetIncomingMessage info = m_peer.CreateIncomingMessage(NetIncomingMessageType.StatusChanged, 4 + reason.Length + (reason.Length > 126 ? 2 : 1));
                info.m_senderConnection = this;
                info.m_senderEndPoint = m_remoteEndPoint;
                info.Write((byte)m_status);
                info.Write(reason);
                m_peer.ReleaseMessage(info);
            }
            else
            {
                // app dont want those messages, update visible status immediately
                m_visibleStatus = m_status;
            }
        }

Usage Example

        /// <summary>
        /// Create a connection to a remote endpoint
        /// </summary>
        public virtual NetConnection Connect(NetEndPoint remoteEndPoint, NetOutgoingMessage hailMessage)
        {
            if (remoteEndPoint == null)
            {
                throw new ArgumentNullException("remoteEndPoint");
            }
            if (m_configuration.DualStack)
            {
                remoteEndPoint = NetUtility.MapToIPv6(remoteEndPoint);
            }

            lock (m_connections)
            {
                if (m_status == NetPeerStatus.NotRunning)
                {
                    throw new NetException("Must call Start() first");
                }

                if (m_connectionLookup.ContainsKey(remoteEndPoint))
                {
                    throw new NetException("Already connected to that endpoint!");
                }

                NetConnection hs;
                if (m_handshakes.TryGetValue(remoteEndPoint, out hs))
                {
                    // already trying to connect to that endpoint; make another try
                    switch (hs.m_status)
                    {
                    case NetConnectionStatus.InitiatedConnect:
                        // send another connect
                        hs.m_connectRequested = true;
                        break;

                    case NetConnectionStatus.RespondedConnect:
                        // send another response
                        hs.SendConnectResponse(NetTime.Now, false);
                        break;

                    default:
                        // weird
                        LogWarning("Weird situation; Connect() already in progress to remote endpoint; but hs status is " + hs.m_status);
                        break;
                    }
                    return(hs);
                }

                NetConnection conn = new NetConnection(this, remoteEndPoint);
                conn.SetStatus(NetConnectionStatus.InitiatedConnect, "user called connect");
                conn.m_localHailMessage = hailMessage;

                // handle on network thread
                conn.m_connectRequested    = true;
                conn.m_connectionInitiator = true;

                m_handshakes.Add(remoteEndPoint, conn);

                return(conn);
            }
        }
All Usage Examples Of Lidgren.Network.NetConnection::SetStatus