1 package com.Inet.lesson1; 2 3 import java.net.InetSocketAddress; 4 5 public class TestInetSocketAddress { 6 public static void main(String[] args) { 7 8 InetSocketAddress socketAddress = new InetSocketAddress("127.0.0.1", 8080); 9 InetSocketAddress socketAddress2 = new InetSocketAddress("localhost", 8080); 10 System.out.println(socketAddress); 11 System.out.println(socketAddress2); 12 13 System.out.println(socketAddress.getAddress()); 14 System.out.println(socketAddress.getHostName());//地址、在这里面改C:\Windows\System32\drivers\etc\hosts 15 System.out.println(socketAddress.getPort());//端口 16 17 } 18 } 19 结果: 20 /127.0.0.1:8080 21 localhost/127.0.0.1:8080 22 /127.0.0.1 23 127.0.0.1 24 8080 25 26 package com.Inet.lesson1; 27 28 import java.net.InetSocketAddress; 29 30 public class TestInetSocketAddress { 31 public static void main(String[] args) { 32 33 InetSocketAddress socketAddress = new InetSocketAddress("127.0.0.1", 8080); 34 InetSocketAddress socketAddress2 = new InetSocketAddress("localhost", 8080); 35 System.out.println(socketAddress); 36 System.out.println(socketAddress2); 37 38 System.out.println(socketAddress.getAddress()); 39 System.out.println(socketAddress.getHostName());//地址、在这里面改C:\Windows\System32\drivers\etc\hosts 40 System.out.println(socketAddress.getPort());//端口 41 42 } 43 } 44 结果: 45 /127.0.0.1:8080 46 loca
原文:https://www.cnblogs.com/duanfu/p/12600074.html