RemoteEndPoint: Identifying the client from the server side

Variant 1: When using TcpListener class for our server there are 2 ways to get the underlying client

            TcpClient client = listener.AcceptTcpClient();

            IPEndPoint remoteEP = (IPEndPoint) client.Client.RemoteEndPoint;


            Socket client = listener.AcceptSocket();

            IPEndPoint remoteEP = (IPEndPoint) client.RemoteEndPoint;

Variant 2: When using the Socket class:

            Socket client = socketServer.Accept();

            IPEndPoint remoteEP = (IPEndPoint) client.RemoteEndPoint;

Then we can very easy get the IPAddress/Port for the client

            IPAddress ip = remoteEP.Address;

            int port = remoteEP.Port;