I am creating a server (desktop based) which listens on a port 4504 using this bit of code
IPAddress[] AddressAr = null;
String ServerHostName = "";
try
{
ServerHostName = Dns.GetHostName();
IPHostEntry ipEntry = Dns.GetHostByName(ServerHostName);
AddressAr = ipEntry.AddressList;
}
catch (Exception) { }
if (AddressAr == null || AddressAr.Length < 1)
{
return "Unable to get local address ... Error";
}
Listener_Socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
Listener_Socket.Bind(new IPEndPoint(AddressAr[0], Port));
Listener_Socket.Listen(-1);
Listener_Socket.BeginAccept(new AsyncCallback(EndAccept), Listener_Socket);
return ("Listening On " + AddressAr[0].ToString() + ":" + Port + "... OK");
Now the problem is that, I want to run this on my server and the value of AddressAr[0] I want to be is the public IP of my server, but this snippet returns the local lan address of the server.
Like I want AddressAr[0] = "180.123.45.6" something [which is the public IP of my server], but with this snippet I am getting AddressAr[0] = "192.168.2.2"
PS: I am running this server as a desktop app and my trials were in the debugging mode.
I'd appreciate any help. Thank You.