how to have the IP of a TcpClient

  • Thread starter Thread starter herbert
  • Start date Start date
H

herbert

hi everybody,

My TcpListener give me a TcpClient, and i would like to have the IP
address of this TcpClient.
I can have a NetworkStream with TcpClient.GetStream(), but I can't read
NetworkStream.Socket that is protected...

I've tried to create a class thats inherits from NetworkStream, but i
can't cast: DerivedNetworkStream dns =
(DerivedNetworkStream)TcpClient.GetStream()
An exeption raises.

how can I do it ?
 
From the TcpClient class docs:
If you want greater flexibility than a TcpClient offers, consider using
AcceptSocket.

Once you have the socket:
IPEndPoint ep = (IPEndPoint)socket.RemoteEndPoint;
Console.WriteLine("Connected to " + ep.Address.ToString() + ":" +
ep.Port);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top