public static void main(String[] args) { InetSocketAddress localhost = new InetSocketAddress("localhost", 8080); System.out.println(localhost.getAddress());//获取地址 System.out.println(localhost.getHostName());//获取主机名 System.out.println(localhost.getHostString());//获取主机字符串 System.out.println(localhost.getPort());//获取端口 }
localhost/127.0.0.1
localhost
localhost
8080