我先创建了一个套接字
ListenSocket=new Socket (ipAddress.AddressFamily,SocketType.Stream ,ProtocolType.Tcp );
用该套接字去侦听特定端口,用ListenSocket.BeginAccept()得到一连接请求后,
再用ListenSocket.EndAccept()结束该连接,
那么我庐怎样去获得发出该请求的主机IP???
请指点~~~~~~~~~~~

解决方案 »

  1.   

    s.Connect(lep)' Using the RemoteEndPoint property.
    Console.WriteLine("I am connected to ")
    Console.WriteLine(IPAddress.Parse(CType(s.RemoteEndPoint, IPEndPoint).Address.ToString()))
    Console.WriteLine("on port number ")
    Console.WriteLine(CType(s.RemoteEndPoint, IPEndPoint).Port.ToString())' Using the LocalEndPoint property.
    Console.WriteLine("My local IpAddress is :")
    Console.WriteLine(IPAddress.Parse(CType(s.LocalEndPoint, IPEndPoint).Address.ToString()))
    Console.WriteLine("I am connected on port number ")
    Console.WriteLine(CType(s.LocalEndPoint, IPEndPoint).Port.ToString())
      

  2.   

    //通过连接请求,并获得接收数据时使用的Socket实例
    EndPoint tempRemoteEP =sock.RemoteEndPoint  ;
    IPEndPoint tempRemoteIP =  ( IPEndPoint ) tempRemoteEP ;
    //获取请求的远程计算机名称
    IPHostEntry host = Dns.GetHostByAddress
    ( tempRemoteIP.Address ) ;
    string sHostName = host.HostName ;