现在的位置: 首页 > 综合 > 正文

RemoteEndPoint: Identifying the client from the server side 得到客户端的ip

2014年01月23日 ⁄ 综合 ⁄ 共 706字 ⁄ 字号 评论关闭
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;
 
or
 
            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;
原文

 

抱歉!评论已关闭.