1.网络通信:
如何定位到一台主机?
IP地址 定位主机, 端口号定位到具体的应用程序
如何在主机之间通信(传输数据)?
网络通信协议
2.IP地址分类
IPv4: 32位

IPv6地址:128位
IPv6地址使用以冒号分隔的十六进制数字。它分为八个16位块,构成一个128位地址方案。

对比IPv4和IPv6:

根据IP地址中的网络号和主机号,可以将IPv4地址分为:A,B,C,D,E这5类


3.特殊IP地址
127.0.0.1:表示本机地址
局域网地址:

4.java中的IP类: InetAddress

没有构造函数,需要通过静态方法来get对象
常用函数:
import java.net.InetAddress;
import java.net.UnknownHostException;
public class D1 {
public static void main(String[] args) throws UnknownHostException {
System.out.println("Get local host ip");
InetAddress ip = InetAddress.getByName("127.0.0.1");
System.out.println(ip);
System.out.println(InetAddress.getByName("localhost"));
System.out.println(InetAddress.getLocalHost());
System.out.println("Get Internet ip");
InetAddress ip2 = InetAddress.getByName("www.google.com");
System.out.println(ip2);
System.out.println(ip2.getAddress());
System.out.println(ip2.getCanonicalHostName());
System.out.println(ip2.getHostAddress());
System.out.println(ip2.getHostName());
}
}
结果:

Reference:
博客主要介绍网络通信相关知识,包括通过IP地址定位主机、端口号定位应用程序,以及网络通信协议。还阐述了IPv4和IPv6的分类、特点及对比,提及特殊IP地址。此外,介绍了Java中的InetAddress类,它无构造函数,需用静态方法获取对象。

809

被折叠的 条评论
为什么被折叠?



