tcpClient and binding on dual homed machine?

  • Thread starter Thread starter Stu
  • Start date Start date
S

Stu

I'm using tcpClient to send data to a pocket pc from the server. The server
is dual homed and tcpClient seems to bind to the first address
(.AddressList(0)) - how do I bind that to another address (.AddressList(1)).
I need to do this because the network adapter for eth0 is on non routable
network that can't talk to anything else (on purpose). This software will
run on many different servers, so I'll need the software to be able to pick
what IP it listens on and sends on.

I know this is probably a newbe questions, but neither of the books that I
have as reference or google has provided me with much of an answer.

Thanks In Advance,

Stu
 
Has two network cards and talks to two seperate networks. Basically I'm
just trying to force the tcpclient to the network card of my choosing.
Should be a fairly simple task, but I'm stumped on how to get there.

Stu
 
I think you call bind, listen then accept to do sockets.
It looks like you need to specify which interface you want to use in the
bind call.
Here is a quote from MSDN Socket.Bind docs.

Before calling Bind, you must first create the local IPEndPoint from which
you intend to communicate data. If you do not care which local address is
assigned, you can create an IPEndPoint using IPAddress.Any as the address
parameter, and the underlying service provider will assign the most
appropriate network address. This might help simplify your application if
you have multiple network interfaces. If you do not care which local port is
used, you can create an IPEndPoint using 0 for the port number. In this
case, the service provider will assign an available port number between 1024
and 5000.
 
You can use the constructor which takes an IP address and port number to
bind your socket to a given adapter. That is, if your RAS IP address is
172.72.0.1 and your Ethernet IP is 172.73.0.1 and you want to use Ethernet
to make your connection to the server, you'd do something like:

xxx = new TcpClient( "172.73.0.1", clientPortNumber );

Paul T.
 
Sorry, previous message showed the wrong constructor used. You want to use
the one which takes an IPEndPoint, passing the local IP you want to bind to
and the local port you want to bind to when you create the IPEndPoint
instance.

Paul T.
 
Back
Top