Esempio n. 1
0
        /// <summary>
        /// This shuts down the server and disconnects all clients.
        /// </summary>
        public void Disconnect()
        {
            if (LocalClient != null)
            {
                OnStopHost.Invoke();
                LocalClient.Disconnect();
            }

            foreach (INetworkConnection conn in connections)
            {
                conn.Disconnect();
            }
            if (transport != null)
            {
                transport.Disconnect();
            }
        }
Esempio n. 2
0
        /// <summary>
        /// This shuts down the server and disconnects all clients.
        /// </summary>
        public void Disconnect()
        {
            if (LocalClient != null)
            {
                OnStopHost.Invoke();
                LocalClient.Disconnect();
            }

            // make a copy,  during disconnect, it is possible that connections
            // are modified, so it throws
            // System.InvalidOperationException : Collection was modified; enumeration operation may not execute.
            var connectionscopy = new HashSet <INetworkConnection>(connections);

            foreach (INetworkConnection conn in connectionscopy)
            {
                conn.Disconnect();
            }
            if (Transport != null)
            {
                Transport.Disconnect();
            }
        }