jop1
jop1

Reputation: 1

Sockets C# and different subnets

I'm trying to implement a socket application for my very frist time. WHen I use:

IPHostEntry ipHostInfo = Dns.Resolve(Dns.GetHostName());
IPAddress ipAddress = ipHostInfo.AddressList[0];
IPEndPoint localEndPoint = new IPEndPoint(ipAddress, 11000);

the localEndPoint IPEndPoint contains "192.168.56.1", that is my address under my VirtualBox network. It should contain my local network ip ("192.168.1.165").

How can I manage it?

I looked over Google but I could find an answer sorry...

Upvotes: 0

Views: 535

Answers (2)

usr
usr

Reputation: 171178

Use IPAddress.Any to simply bind on all local interfaces. You do not need to find out a specific local IP for most scenarios.

Note, that you are throwing away all but one address. No wonder that you are only getting one.

There is no such thing as the local IP. It is a set.

Upvotes: 1

fejesjoco
fejesjoco

Reputation: 11903

Your virtual machine doesn't know anything about the network interfaces in the outside world. You can only find out your local addresses with the NetworkInterface.GetAllNetworkInterfaces() method (see here). Anything else should be a configuration setting.

Upvotes: 1

Related Questions