/// <summary> /// Disconnects from the remote server and cleans up resources /// </summary> /// <param name="e">An exception if one occurred</param> public void Disconnect(Exception e = null) { _reader?.Stop(); _reader = null; _writer?.Stop(); _writer = null; _networkStream?.Dispose(); _networkStream = null; _client?.Close(); _client = null; OnDisconnected(e); }
/// <summary> /// Disconnects from the remote server and cleans up resources /// </summary> /// <param name="e">An exception if one occurred</param> public void Disconnect(Exception e = null) { if (_client == null) { return; } //var remoteEndPoint = _client.Client.RemoteEndPoint.As<IPEndPoint>(); //retain a reference _reader?.Stop(); _reader = null; _writer?.Stop(); _writer = null; _networkStream?.Dispose(); _networkStream = null; #if NETSTANDARD1_3 || NETSTANDARD1_4 _client?.Dispose(); #else _client?.Close(); #endif _client = null; OnDisconnected(RemoteEndPoint, e); }