TCP:打电话--连接--接了--通话
UDP:发短信--发送完了就完事了--接收
package lesson01;
import java.net.InetAddress;
import java.net.UnknownHostException;
//测试IP
public class TestInetAddress {
public static void main(String[] args) {
try {
InetAddress inetAddress1 = InetAddress.getByName("127.0.0.1");
System.out.println(inetAddress1);
InetAddress inetAddress2 = InetAddress.getByName("localhost");
System.out.println(inetAddress2);
InetAddress inetAddress3 = InetAddress.getLocalHost();
System.out.println(inetAddress3);
InetAddress inetAddress4 = InetAddress.getByName("www.baidu.com");
System.out.println(inetAddress4);
} catch (UnknownHostException e) {
e.printStackTrace();
}
}
}
/127.0.0.1
localhost/127.0.0.1
LAPTOP-I5E76G9L/10.82.33.145
www.baidu.com/220.181.38.150