Esempio n. 1
0
 /// <summary>
 /// Closes all connections which are bound to this object.
 /// </summary>
 /// <param name="closeReason">The close reason.</param>
 /// <param name="callCloseEvent">If the instance should call the connectionLost event.</param>
 public void Shutdown(CloseReason closeReason, bool callCloseEvent = false)
 {
     if (IsAlive_TCP)
     {
         tcpConnection.Close(closeReason, callCloseEvent);
     }
     if (IsAlive_UDP)
     {
         udpConnection.Close(closeReason, callCloseEvent);
     }
 }
Esempio n. 2
0
        /// <summary>
        /// Handles when a <see cref="UdpConnection"/> successfully connects to the server.
        /// </summary>
        /// <param name="tcpConnection">The parent <see cref="TcpConnection"/>.</param>
        /// <param name="udpConnection">The connected <see cref="UdpConnection"/>.</param>
        private void udpConnectionReceived(TcpConnection tcpConnection, UdpConnection udpConnection)
        {
            if (!AllowUDPConnections || this[tcpConnection].Count >= UDPConnectionLimit)
            {
                CloseReason closeReason = (this[tcpConnection].Count >= UDPConnectionLimit) ? CloseReason.UdpLimitExceeded : CloseReason.InvalidUdpRequest;
                tcpConnection.Close(closeReason, true);
                return;
            }

            this[tcpConnection].Add(udpConnection);
            udpConnection.NetworkConnectionClosed += connectionClosed;
            KnownTypes.ForEach(udpConnection.AddExternalPackets);

            //Inform all subscribers.
            if (connectionEstablished != null &&
                connectionEstablished.GetInvocationList().Length > 0)
            {
                connectionEstablished(udpConnection, ConnectionType.UDP);
            }
        }
        /// <summary>
        /// A UDP connection has been established.
        /// </summary>
        /// <param name="arg1">The arg1.</param>
        /// <param name="arg2">The arg2.</param>
        /// <exception cref="NotImplementedException"></exception>
        private void udpConnectionReceived(TcpConnection tcpConnection, UdpConnection udpConnection)
        {
            if (!AllowUDPConnections || this[tcpConnection].Count >= UDPConnectionLimit)
            {
                CloseReason closeReason = (this[tcpConnection].Count >= UDPConnectionLimit) ? CloseReason.UdpLimitExceeded : CloseReason.InvalidUdpRequest;
                tcpConnection.Close(closeReason);
                tcpOrUdpConnectionClosed(closeReason, tcpConnection);
                return;
            }

            this[tcpConnection].Add(udpConnection);
            udpConnection.ConnectionClosed += tcpOrUdpConnectionClosed;

            //Inform all subscribers.
            if (connectionEstablished != null &&
                connectionEstablished.GetInvocationList().Length > 0)
                connectionEstablished(udpConnection, ConnectionType.UDP);
        }
 /// <summary>
 /// Closes all connections which are bound to this object.
 /// </summary>
 /// <param name="closeReason">The close reason.</param>
 /// <param name="callCloseEvent">If the instance should call the connectionLost event.</param>
 public void Shutdown(CloseReason closeReason, bool callCloseEvent = false)
 {
     tcpConnection.Close(closeReason, callCloseEvent);
     udpConnection.Close(closeReason, callCloseEvent);
 }