When i call the function
Socket.Connect(ip,port)
If i have active more than one interface, which source ip is chosen?
Is the correct way to set the ip of a client socket with the Bind operation?
The Socket.LocalEndPoint
property contains the local IP address which is set according to the routing table.
If you wish to decide on the local endpoint yourself you can use the Bind
method.
aSocket.Bind(theLocalEndpoint);
See the MSDN article here for more information on binding to a custom endpoint.
Windows does not guarantee a specific network interface with Bind
, it relies upon the routing table to choose which interface is used for the socket, based on the local endpoint specified.
Please see [Using a specific network interface for a socket in windows for a more complete explanation.