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?
-
You will have to edit your question and clarify your problem. – Dalija Prasnikar Jun 10 '22 at 09:26
-
Could you add your code with the problem also? – Jimmy Smith Jun 10 '22 at 13:31
1 Answers
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
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).

- 555,201
- 31
- 458
- 770
-
can indy do it? or is there any other way besides ipbind, for example adding a route in windows? – Blawjack Jun 10 '22 at 18:51
-