Kenzo
Kenzo

Reputation: 1837

What is the C# equivalent for Java Socket.getInetAddress()?

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

Answers (2)

onurbaysan
onurbaysan

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

Carl Winder
Carl Winder

Reputation: 948

If this is to get the connected sockets IP you can use this

Upvotes: 1

Related Questions