LKCamelot.Connection.Disconnect C# (CSharp) Method

Disconnect() public method

public Disconnect ( ) : void
return void
        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 { }
                }
            }
        }

Usage Example

Example #1
0
        private void RemoveConnection(Connection connection, bool raiseEvent)
        {
            if (connection == null)
                return;
            connection.Disconnect();

            if (connection.Client != null
                && connection.Client.player != null)
            {
                connection.Client.player.InstancedObjects.Clear();
                connection.Client.player.m_Buffs.Clear();
            }

            // Remove the connection from the dictionary and raise the OnDisconnection event.
            lock (ConnectionLock)
            {
                if (Connections.Contains(connection))
                    Connections.Remove(connection);
            }

            if (raiseEvent)
                NotifyRemoveConnection(connection);
        }