On Jan 16, 2:32 pm, Chris Shepherd <c...@nospam.chsh.cawrote:
paal.andreas...@gmail.com wrote:
I have a problem. I have two instances of a client-server application
running on two different machines A and B.
A has a listening service, that listens for connections from B
B has a listening service, that listens for connections from A
The problem is what IP to bind the listening service to. I can find
all local ip-addresses this way:
[...]
But how on earth do I know which one to bind and listen to? There's a
mix of IPv4 and IPv6 addresses, virtual vmware addresses, one from the
wireless wifi card and one from the ethernet cable.
Yup. Knowing which one to bind to depends on the network you want to listen on.
If A is publishing its IP to B, then it really doesn't matter what B publishes
on does it? You could just create your IPEndPoint using IPAddress.Any as the
IPAdress argument to just grab whatever the system thinks is best, i.e.:
Int32 port = 10101;
IPEndPoint myEndPoint = new IPEndPoint(IPAddress.Any, port);
Chris.
On the server-side I can have the service bind to IPAddress.Any ok,
but the client still needs to know the "correct" IP address for the
server. Iterating thought hostEntry.AddressList returns several
addresses, how do I know which one to use? I'd really like to automate
this and not ask the user "which of the following IP addresses is the
right one" if you follow.
Like I said, I put the IP address in a SQL database which is shared
between the clients. The client is then supposed to use this IP to
access the service directly. But on a given machine AddressList might
return several different IP addresses, but only one is actually
enabling access from outside the computer. The problem is to identify
which one I should but in the database.
Example, on a give computer I get two different IP Addressen in the
hostEntry.AddressList:
0: 10.70.0.125 InterNetwork
1: 10.0.0.14 InterNetwork
In this case I know that entry 0 is a VPN tunnel to another network
and is not interesting. It's 10.0.0.14 that my service is accessible
from the other clients in the network.
Can I detect which of these are used with the default gateway? Or is
that a dead end?