private void ConnectSocket(Uri uri) { var innerErrors = new List <Exception>(); var addresses = _resolver.Resolve(uri.Host); foreach (var address in addresses) { try { ConnectSocket(address, uri.Port); return; } catch (Exception e) { var actualException = e; if (actualException is AggregateException) { actualException = ((AggregateException)actualException).GetBaseException(); } innerErrors.Add(new IOException( $"Failed to connect to server '{uri}' via IP address '{address}': {actualException.Message}", actualException)); } } // all failed throw new IOException( $"Failed to connect to server '{uri}' via IP addresses'{addresses.ToContentString()}' at port '{uri.Port}'.", new AggregateException(innerErrors)); }
public IPAddress[] Resolve(string hostname) { if (_getHostByNameMethod != null) { var result = _getHostByNameMethod.Invoke(null, new object[] { hostname, true }); if (result is IPHostEntry resolved) { return(resolved.AddressList); } } return(_fallBackResolver.Resolve(hostname)); }
public IPAddress[] Resolve(string hostname) { return(_original.Resolve(_target.Host)); }