How to connect using specific network adapter?

Viewed 916

We are using Delphi Berlin 10.2

We have an application that runs on devices with 2 or more ethernet adapters. It's mandatory for us to choose a specific network adapter.

I researched and failed to find a way to do this using Indy, Synapse, or even Winsock.

The connect methods don't offer this option, they offer only destination IP and port.

Is there a way to do this?

1 Answers

You need to bind() the client socket to the local IP address of the desired network interface, then connect() will reach out to the server's IP:port using the network that the interface is attached to.

Indy has properties for that purpose, for instance the BoundIP property of TIdTCPClient.

I'm sure Synapse (and most other networking libraries) has its own equivalent for this, too.

Related