Client Socket Info

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi, I want to retrive information from a System.Net.Sockets.Socket object
client, like the ip address or the name of the client; how can I do that???
thanks.
 
Socket s; //already connected

// Using the RemoteEndPoint property.
Console.WriteLine ("I am connected to " +
IPAddress.Parse(((IPEndPoint)s.RemoteEndPoint).Address.ToString ()) +
"on port number " + ((IPEndPoint)s.RemoteEndPoint).Port.ToString ()
);

// Using the LocalEndPoint property.
Console.WriteLine ("My local IpAddress is :" +
IPAddress.Parse (((IPEndPoint)s.LocalEndPoint).Address.ToString ()) +
"I am connected on port number " +
((IPEndPoint)s.LocalEndPoint).Port.ToString ()
);

to resolve the name of the client you can use Dns.Resolve for the obtained
ip address
 
Back
Top