public Connection(Server server, Socket socket) { if (server == null) throw new ArgumentNullException("server"); if (socket == null) throw new ArgumentNullException("socket"); this._server = server; this._Socket = socket; }
/// <summary> /// Kills the connection to remote endpoint. /// </summary> public void Disconnect() { Logger.Trace("Disconnect() | server: " + _server); if (_server != null) { // Use temp assignment to preven recursion. Server tempServer = _server; _server = null; tempServer.Disconnect(this); } if (this.TLSStream != null) { try { this.TLSStream.Close(); } finally { this.TLSStream.Dispose(); this.TLSStream = null; } } 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 { this.Socket.Dispose(); this.Socket = null; } } }