Javaweb 网页编程 B/S架构
TCP/IP 网络编程 C/S架构

1.2 网络通信的要素

  • 如何实现网络通信
    1、通信双方的地址:

    IP 192.168.1.1
    端口号
    192.168.16,124::5900

    2、网络通信的协议

    http,ftp,smtp,tcp,udp...
    tcp/ip

    image.png

image.png

1.3 IP

public class InetAddress

* IP用来唯一定位一台网络上的计算机

  • 重要的IP:
    127.0.0.1 表示本机的ip localhost,称为环回地址
    image.png
  • IP地址的分类

    【分类方法一:IPV4 / IPV6】
    IPV4:

    使用32位(4字节)地址,十进制,每段有0-255,一共42亿地址。
    例如127.0.0.1

    IPV6:

    image.png
    这里显示的不完整,还除以了16
    长度为128位,是IPv4地址长度的4倍,8个无符号整数构成,十六进制
    2001:0DB8:0000:0023:0008:0800:200C:417A

    【分类方法二:公网(互联网) / 私网(局域网)】
    ABCD类地址
    192.168.xx.xx 是专门给组织内部使用的

    image.png
    A类:1.0.0.0-126.0.0.0
    B类:128.1.0.0-191.255.0.0
    C类:192.0.1.0-223.255.255.0

  • 域名 方便记ip
    操作:
    InetAddress 没有构造函数

    static InetAddres getByAddress(byte[] addr)
    返回InetAddress对象

    创建对象用静态方法:

    InetAddress ia = InetAddress.getByAddress("127.0.0.1");
    InetAddress ia = InetAddress.getByAddress("localhost");
    InetAddress ia = InetAddress.getByAddress("www.baidu.com");

    获取ip地址、域名

    getCanonicalHostAddress();
    getHostAddress();
    getHostName();

    image.png


MeeWoW
18 声望1 粉丝

加油