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);
 
Back
Top