应该
CAddress.getHostAddress()获得ip
socket.getPort()获得端口

解决方案 »

  1.   

    握手上有手册,可我在InetAddress类结构里,没有找到getHostAddress()和getPort,不知它返回值是什么类型,我当作String类型,仅仅修改了一句:
    System.out.println("Client from :"+CAddress.getHostAddress());
    但还是返回0.0.0.0 ,请问为什么?
      

  2.   

    先判断socket是否为null
    CAddress=server.getInetAddress();
    bytes=CAddress.getAddress();String ip = new String(bytes);
    System.out.println("Client from :"+ip);
      

  3.   

    更正:先判断socket是否为nullCAddress=socket.getInetAddress();//应为socket不是server
    bytes=CAddress.getAddress();String ip = new String(bytes);
    System.out.println("Client from :"+ip);