Disconnect() public method

public Disconnect ( Connection connection ) : void
connection Connection
return void
Example #1
0
        public void Disconnect()
        {
            //      Logger.Trace("Disconnect() | server: " + _server);
            try
            {
                this.Client.player.loggedIn = false;
            }
            catch { }
            if (_server != null)
            {
                // Use temp assignment to preven recursion.
                Server tempServer = _server;
                _server = null;
                tempServer.Disconnect(this);
            }

            if (this.Socket != null)
            {
                try
                {
                    this.Socket.Shutdown(SocketShutdown.Both);
                    this.Socket.Close();
                }
                catch (Exception)
                {
                    // Ignore any exceptions that might occur during attempt to close the Socket.
                }
                finally
                {
                    try
                    {
                        this.Socket.Dispose();
                        this.Socket = null;
                    }
                    catch { }
                }
            }
        }