1

I'm using Delphi 10.2 Tokyo. I have 4 internet sources with 4 LANs. I want to make a program using TNetHttpClient. How do I direct it to use a specific internet source?

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
Blawjack
  • 53
  • 5

1 Answers1

1

Unfortunately, TNetHttpClient does not provide the ability to bind it to a specific LAN. If you need this capability, you will have to find another HTTP library that can do this.

UPDATE:

After doing some reading, it turns out that on Windows at least, binding a socket for an outbound connection only sets the source IP for the socket's packets, but prior to Vista the actual adapter used for making an IPv4 connection is determined solely by Windows' routing tables, the application can't force a specific IPv4 adapter to be used. But for IPv6 traffic, and for IPv4 traffic on Vista+, binding a socket to a specific adapter should work in most cases.

Q175396: Windows Socket Connection from a Multiple-Homed Computer

Strong and Weak Host Models

Using a specific network interface for a socket in windows

For instance, Indy's TIdHTTP has a public BoundIP property for binding its socket to a network interface's IP (on platforms that require an interface name instead, you can use the TIdHTTP.OnSocketAllocated or TIdHTTP.OnAfterBind event to call the TIdHTTP.Socket.Binding.SetSockOpt() method, such as for using the SO_BINDTODEVICE option on Linux).

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770