2021-09-25 网络编程(IP地址)
2021-10-28 本文已影响0人
Denholm
IP地址
1.网络中设备的标识
2.不易记忆,可用主机名
3.本地回环地址:127.0.0.1,主机名:localhost
端口号
1.用于标识进程的逻辑地址,不同进程的标识
2.有效端口:065535,其中01024系统使用或者保留端口
传输协议
1.通讯的规则
2.常见协议:TCP,UDP
import java.net.InetAddress;
import java.net.UnknownHostException;
public class IPDemo {
public static void main(String[] args) {
InetAddress ia;
try {
ia = InetAddress.getLocalHost();
System.out.println(ia.toString());
System.out.println("address: " + ia.getHostAddress());
System.out.println("hostName:" + ia.getHostName());
ia = InetAddress.getByName("www.baidu.com");
System.out.println("address: " + ia.getHostAddress());
System.out.println("hostName:" + ia.getHostName());
} catch (UnknownHostException e) {
e.printStackTrace();
}
}
}