File tree Expand file tree Collapse file tree 1 file changed +6
-2
lines changed
snippets/csharp/System.Net.Http/SocketsHttpHandler/ConnectCallback Expand file tree Collapse file tree 1 file changed +6
-2
lines changed Original file line number Diff line number Diff line change 1- using System ;
1+ using System ;
22using System . IO ;
33using System . Net ;
44using System . Net . Http ;
55using System . Net . Sockets ;
6+ using System . Threading ;
67using System . Threading . Tasks ;
78
89class HttpClientHandler_SecureExample
@@ -14,14 +15,17 @@ static async Task Main()
1415
1516 handler . ConnectCallback = async ( ctx , ct ) =>
1617 {
18+ DnsEndPoint dnsEndPoint = ctx . DnsEndPoint ;
19+ IPAddress [ ] addresses = await Dns . GetHostAddressesAsync ( dnsEndPoint . Host , dnsEndPoint . AddressFamily , ct ) ;
1720 var s = new Socket ( SocketType . Stream , ProtocolType . Tcp ) { NoDelay = true } ;
1821 try
1922 {
2023 s . SetSocketOption ( SocketOptionLevel . Socket , SocketOptionName . KeepAlive , true ) ;
2124 s . SetSocketOption ( SocketOptionLevel . Tcp , SocketOptionName . TcpKeepAliveTime , 5 ) ;
2225 s . SetSocketOption ( SocketOptionLevel . Tcp , SocketOptionName . TcpKeepAliveInterval , 5 ) ;
2326 s . SetSocketOption ( SocketOptionLevel . Tcp , SocketOptionName . TcpKeepAliveRetryCount , 5 ) ;
24- await s . ConnectAsync ( ctx . DnsEndPoint , ct ) ;
27+
28+ await s . ConnectAsync ( addresses , dnsEndPoint . Port , ct ) ;
2529 return new NetworkStream ( s , ownsSocket : true ) ;
2630 }
2731 catch
You can’t perform that action at this time.
0 commit comments