File tree Expand file tree Collapse file tree 1 file changed +5
-3
lines changed
snippets/csharp/System.Net.Http/SocketsHttpHandler/ConnectCallback Expand file tree Collapse file tree 1 file changed +5
-3
lines changed Original file line number Diff line number Diff line change 1- using System ;
2- using System . IO ;
1+ using System ;
32using System . Net ;
43using System . Net . Http ;
54using System . Net . Sockets ;
@@ -14,14 +13,17 @@ static async Task Main()
1413
1514 handler . ConnectCallback = async ( ctx , ct ) =>
1615 {
16+ DnsEndPoint dnsEndPoint = ctx . DnsEndPoint ;
17+ IPAddress [ ] addresses = await Dns . GetHostAddressesAsync ( dnsEndPoint . Host , dnsEndPoint . AddressFamily , ct ) ;
1718 var s = new Socket ( SocketType . Stream , ProtocolType . Tcp ) { NoDelay = true } ;
1819 try
1920 {
2021 s . SetSocketOption ( SocketOptionLevel . Socket , SocketOptionName . KeepAlive , true ) ;
2122 s . SetSocketOption ( SocketOptionLevel . Tcp , SocketOptionName . TcpKeepAliveTime , 5 ) ;
2223 s . SetSocketOption ( SocketOptionLevel . Tcp , SocketOptionName . TcpKeepAliveInterval , 5 ) ;
2324 s . SetSocketOption ( SocketOptionLevel . Tcp , SocketOptionName . TcpKeepAliveRetryCount , 5 ) ;
24- await s . ConnectAsync ( ctx . DnsEndPoint , ct ) ;
25+
26+ await s . ConnectAsync ( addresses , dnsEndPoint . Port , ct ) ;
2527 return new NetworkStream ( s , ownsSocket : true ) ;
2628 }
2729 catch
You can’t perform that action at this time.
0 commit comments