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