Reputation: 1837
I am developing a http program in C# while referring to some source code written in Java! I would like to know if there is a C# equivalent way for the the method getInetAddress() . In other words how to get the ip address from a socket object in C# ?
Upvotes: 0
Views: 3081
Reputation: 1258
socket.Connect (lep);
// Using the RemoteEndPoint property.
Console.WriteLine ("I am connected to " + IPAddress.Parse (((IPEndPoint)socket.RemoteEndPoint).Address.ToString ()) + "on port number " + ((IPEndPoint)socket.RemoteEndPoint).Port.ToString ());
// Using the LocalEndPoint property.
Console.WriteLine ("My local IpAddress is :" + IPAddress.Parse (((IPEndPoint)socket.LocalEndPoint).Address.ToString ()) + "I am connected on port number " + ((IPEndPoint)socket.LocalEndPoint).Port.ToString ());
http://msdn.microsoft.com/en-us/library/system.net.sockets.socket.localendpoint.aspx
Upvotes: 2