Jump to content
Angus Robertson

WSAConnectByList API, connect to list of IPs

Recommended Posts

When opening a new connection to a remote host, ICS does a DNS lookup that may return several IP addresses, but is only able to connect to one of those addresses, usually the first in the list, unless changed in the onDnsLookup event.  An application that wants to try to connect to another IP after failure needs to retry the connect, selecting another IP from DnsResultList.  Handling this automatically has never been implemented in ICS.

 

Windows has a Winsock2 API WSAConnectByList that takes a list of IP addresses and attempts to connect to each in turn until one succeeds, or a timeout is reached.  Only catch is this is a blocking request, so the application will not process messages until it completes, which is rare in ICS.

 

This could be added without much effort as an option in TWSocket to avoid applications needing to handle the failures and next IP attempts using code (how many of us bother?).

 

Ideally, ICS would handle multiple attempts using events and timeouts, but this is rather more complex to write and test.

 

Would connect to list of IPs be a feature you'd use?

 

Angus

 

Share this post


Link to post

Never used WSAConnectByList, i barely remember testing it, but blocking only without overlapped makes it usable only in specific cases.

 

My suggestion is neither approaches, implement connect with multiple socket at the same time, one Select will do and can be used with up to 64 IPs, the first connect will be used the rest will be closed, this how i do it.

lets say you resolved a host (they almost always returned in random order), i pair one IPv4 with IPv6 and connect to them both, the fastest kept and the other dropped without sending anyting.

 

On side note; IPv6 sometimes outperform IPv4, but not always, my ISP doesn't provide IPv6 in my region, so i use 6in4 tunnels on my router, the tunnels from two providers http://tb.netassist.ua/ and https://tunnelbroker.net/ , the setting are on the router and have punch of end points, now; how they do perform is unpredictable, connecting to north America using NA is slow as turtle, and connecting to Asia using HE is slower then IPv4 by a lot like 2 seconds, yet with NA IPv6 to EU is faster than IPv4, this is just a suggestion to enhance the quality and the speed of the connection by selecting the faster SYN/ACK.

 

Hope that help.

Share this post


Link to post

While opening multiple connections would be good, it is not trivial, which is the benefit of WSAConnectByList.  

 

ICS does support IPv6, the IP selected depends on the TSocketFamily specified, so may be the first IPv6 address if both are available.  But it does not try others if the first fails, and my office IPv6 connection is currently down due to misconfiguration at my ISP (not their opinion).  Currently, IPv6 testing is done on my two hosted servers, I really should setup a VPN to one of them.  

 

So it's important for applications to be able to select TSocketFamily, to prefer or disable IPv6 depending on circumstance.  

 

Angus

 

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×