Created
November 28, 2019 20:22
-
-
Save kadukf/119a414218f7eb974005aba22b74be70 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Program | |
{ | |
static async Task Main(string[] args) | |
{ | |
Console.WriteLine("Starting, press a key to continue ..."); | |
Console.ReadKey(); | |
var ips = await Dns.GetHostAddressesAsync("www.google.com"); | |
foreach (var ipAddress in ips) | |
{ | |
Console.WriteLine(ipAddress.AddressFamily == AddressFamily.InterNetworkV6 ? ipAddress.MapToIPv6().ToString() : ipAddress.MapToIPv4().ToString()); | |
} | |
var socketsHandler = new SocketsHttpHandler | |
{ | |
PooledConnectionLifetime = TimeSpan.FromSeconds(60), | |
PooledConnectionIdleTimeout = TimeSpan.FromMinutes(20), | |
MaxConnectionsPerServer = 20, | |
}; | |
var client = new HttpClient(socketsHandler); | |
var tasks = Enumerable.Range(0, 2000).Select(i => client.SendAsync( | |
new HttpRequestMessage(HttpMethod.Get, "https://www.google.com") | |
{ | |
// turning ON HTTP2 per message, it can be set also globally for all messages | |
Version = HttpVersion.Version20 | |
})); | |
await Task.WhenAll(tasks); | |
Console.WriteLine("Press a key to exit..."); | |
Console.ReadKey(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment