determine IP address for TCPListener

K

Keith Langer

I have a TCPListener which needs to listen on my LAN IP as well as the
loopback address. In VS.Net 2002 the TCPListener constructor could
accept the port as an argument and it automatically bound to all
network adapters (this is also how it worked with VB6). Now that
constructor is obsolete, and the new one requires an IPEndPoint or
IPAddress.

How could I listen on the same port on all network adapters using
VS.Net 2003? I'd rather not use DNS.

thanks,
Keith
 
S

Sunny

From the docs (msdn) about TcpListener(IPEndpoint) constructor:

Remarks
This constructor allows you to specify the local IP address and port
number on which to listen for incoming connection attempts. Before using
this construcor, you must create an IPEndPoint using the desired local
IP address and port number. Pass this IPEndPoint to the constructor as
the localEP parameter.

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.

Does it help?

Sunny
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top