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 ;
2
2
using System . IO ;
3
3
using System . Net ;
4
4
using System . Net . Http ;
5
5
using System . Net . Sockets ;
6
+ using System . Threading ;
6
7
using System . Threading . Tasks ;
7
8
8
9
class HttpClientHandler_SecureExample
@@ -14,14 +15,17 @@ static async Task Main()
14
15
15
16
handler . ConnectCallback = async ( ctx , ct ) =>
16
17
{
18
+ DnsEndPoint dnsEndPoint = ctx . DnsEndPoint ;
19
+ IPAddress [ ] addresses = await Dns . GetHostAddressesAsync ( dnsEndPoint . Host , dnsEndPoint . AddressFamily , ct ) ;
17
20
var s = new Socket ( SocketType . Stream , ProtocolType . Tcp ) { NoDelay = true } ;
18
21
try
19
22
{
20
23
s . SetSocketOption ( SocketOptionLevel . Socket , SocketOptionName . KeepAlive , true ) ;
21
24
s . SetSocketOption ( SocketOptionLevel . Tcp , SocketOptionName . TcpKeepAliveTime , 5 ) ;
22
25
s . SetSocketOption ( SocketOptionLevel . Tcp , SocketOptionName . TcpKeepAliveInterval , 5 ) ;
23
26
s . SetSocketOption ( SocketOptionLevel . Tcp , SocketOptionName . TcpKeepAliveRetryCount , 5 ) ;
24
- await s . ConnectAsync ( ctx . DnsEndPoint , ct ) ;
27
+
28
+ await s . ConnectAsync ( addresses , dnsEndPoint . Port , ct ) ;
25
29
return new NetworkStream ( s , ownsSocket : true ) ;
26
30
}
27
31
catch
You can’t perform that action at this time.
0 commit comments