[Mono-list] How to listen on local socket

Jörg Rosenkranz joergr@voelcker.com
Fri, 1 Aug 2003 16:35:17 +0200

Maybe this is a simple question but I'm desperately searching a way to do this:

I want create a TCP server app and need to listen to a local socket.
How do I create the local endpoint?

I tried it 2 different ways:
	IPHostEntry ipHostInfo = Dns.Resolve(Dns.GetHostName());		// get local Hostname
	IPAddress   ipAddress = ipHostInfo.AddressList[0];			// get first IP-Address from Host
	IPEndPoint localEndPoint = new IPEndPoint(ipAddress, 4444);		// connect to port

  This works under Windows but under Linux/Mono the address is
  Other addresses aren't in the AddressList.

  I know this is not the preferred way.

	IPEndPoint localEndPoint = new IPEndPoint(IPAddress.Any, 4444);

  This works under Windows, too. Linux: Loopback device...

How do I get the right IP address for the first (all?) network card(s)?