Java network programming (the latest version 2021)

Network overview

In simple terms, a network is a group of computers connected together to share data and resources.

According to geographic coverage, computer networks can be divided into local area networks, metropolitan area networks and wide area networks.

Local area network: similar to a switch or router, which can be used by people in the same classroom.
Metropolitan area network: similar to cable TV, such as Foshan Cable TV, which can only be used in Foshan area.
Wide area network: country to global.

Note :
Switch: IP address is freely obtained, not assigned by switch
Router: IP address is assigned
by router Nowadays most routers are equipped with switches and can be used as switches.

Insert picture description here
Insert picture description here
Insert picture description here

Network hierarchical model

Tips :
Do you know network transmission?
It should express that you can transmit the network.
Do you know mathematics and physics?
I have studied mathematics and physics in high school.
Application  table  meeting  transmission  network  data  material The
Insert picture description here
network layered model is the same as the organizational structure of a company. The information transmission on the network is also responsible for different tasks by different levels. However, every computer manufacturer adopts a private network model, which will bring a lot of trouble to communication. The International Standard Organization (ISO) promulgated the Open System Interconnection (OSI) reference model in 1984. The OSI reference model is an open architecture. It stipulates that the network is divided into seven layers, and each layer plays a different role in the transmission of network information.
TCP/IP mode (Transmission Control Protocol/Network Interconnection Protocol)

Insert picture description here

IP address introduction ( click here for details )

The network is so huge, it is necessary to interconnect so many computers to share information, so how to find the target computer in the network? Let's take the mailing process as an example to analyze this problem. First of all, you must know the address of the other party, and then write the address of the recipient on the envelope, so that the postman can correctly deliver the letter to the other party based on the address. In addition, write the sender's address at the end of the email, and the other party can reply according to the address. It can be seen that the address is the key factor in the contact between the two parties.

Similarly, to achieve communication between two computers, both parties must have addresses. In the network, a logical address with a hierarchical structure is used to identify a host. This address is called an IP address. The IP address uniquely identifies each computer in the network.

The IP address has 32 bits, composed of 4 8-bit binary numbers, and each 8 bits are separated by dots, such as 11000000.10101000.00000010.00010100. Because binary is inconvenient to memorize and has poor readability, it is usually converted into a decimal number, such as 196.168.2.20. Therefore, an IP address is usually represented by a decimal number separated by 3 dots, called dotted decimal.

The IP address contains two parts: the network address and the host address. Among them, the network address determines the maximum number of networks that can be allocated, and the host address determines the maximum number of computers that can exist in a network. According to the number of bits in the network address and the host address, IP addresses are divided into five categories: A, B, C, D, and E. Among them, three types of A, B, and C are commonly used. The network address of the IP address is uniformly assigned by the Internet Assigned Numbers Authority (IANA) to ensure the uniqueness of the IP address.

Insert picture description here
For example,
IP address: 192.168.0.181,
4 groups of 32 bits, one group of 8 bits: 0-255
Type C: the first 3 segments are network addresses, and the last segment is the host address

Special IP address:
0.0.0.0: indicates the machine;
127.0.0.1: indicates the loopback address of the machine, usually by ping this address on the machine to check whether the TCP/IP protocol is installed correctly;
localhost: the address of the machine;

Important concepts and functions related to the network

Port:
A computer in the network can usually use multiple processes to provide network services at the same time. Therefore, in addition to the IP address, each host has several port numbers, which are used to distinguish which process the data is sent to or from which process when sending and receiving data. The port is the entrance and exit of the communication between the computer and the outside world. It is a 16-bit integer ranging from 0 to 65535 (216-1).

  在同一台主机上,任何两个进程不能同时使用同一个端口。

Notes:

Port number within 1000: It is not recommended because it is occupied by the system by default.
Common port:
Database: 3306
Tomcat: 8080
My sql: 1433
Oracle: 1521
Http: 80

Domain name and DNS domain name resolution:

    在刚才的内容中已经提到,IP地址唯一定位一台计算机,也就是说只有通过IP地址才能找到一个网中的主机。那么,
    为什么在上网的时候轻松地输入一个网址,我们就能够获得这个远程的Web服务器提供的资源呢?例如,
    为什么在浏览器的地址栏中输入 www.baidu.com 就能进入"百度"网站呢?难道它没有IP地址吗?答案当然是否定的。
    
   人们希望记忆名字而不是枯燥的数字,因此就需要一个系统将一个名称映射为它的IP地址。
   DNS(Domain Name System,域名系统) 被广泛使用,用于将域名映射成ip地址。

Note :
Domain name resolution is simply to convert a web address (domain name) into an IP address.
DNS: You can configure your own domain name resolution server: 114.114.114.114 or 10.10.10.10

DNS

How does the DNS server resolve the domain name? As shown in the figure below, enter the domain name www.baidu.com in the browser, and the host must know its IP address before making a request to www.baidu.com. The host will call the domain name resolution program, send information to the set DNS server, and request the IP address of www.baidu.com. If the local DNS server does not store the corresponding information, it will send the information to the root DNS server to obtain the .com DNS server And then send a query request to the .com DNS server to obtain the IP address of www.baidu.com, and finally obtain the IP address of www.baidu.com.
Insert picture description here
Equipment used in network communication
Physical hardware equipment: computers, network cards, switches, routers, etc.
Software equipment: protocols, (domain protocol addresses) IP addresses

Network communication protocol

网络通信协议是为了在网络中不同的计算机之间进行通信而建立的规则、标准或约定的集合,
它规定了网络通信时,数据必须采用的格式以及这些格式的意义。就好像人们在交谈时约定都使用英语或都使用普通话一样。

In network programming, the commonly used network protocols are as follows:

1. TCP/IP protocol family ( learn more )

TCP/IP是Transmission Control Protocol /Internet Protocol的简称。

它是用于计算机网络通信的协议集,即协议族。该协议族是 Internet 最基本的协议,
它不依赖于任何特定的计算机硬件或操作系统,提供开放的协议标准。

目前,绝大多数的网络操作系统都提供对该协议族的支持,它已经成为 Internet的标准协议。

TCP/IP protocol suite includes many protocols such as IP protocol, TCP protocol, UDP protocol and ARP protocol. Its core protocol is IP protocol and TCP protocol, so the TCP/IP protocol suite is sometimes referred to as TCP/IP protocol for short.

2. TCP protocol

(Understand the process of three-way handshake and four-way wave: click here )

TCP is the abbreviation of Transmission Control Protocol, and the Chinese name is Transmission Control Protocol. TCP is a connection-oriented, reliable, byte stream-based transport layer communication protocol.

TCP requires that both parties in communication must establish a connection before they start communication. Both parties in communication can transmit data at the same time. It is full-duplex, thus ensuring the correct transmission of data.

3.UDP protocol

UDP is the abbreviation of User Datagram Protocol, and the Chinese name is called User Datagram Protocol.

The UDP protocol is a connectionless protocol. Before data transmission, the client and server do not establish and maintain a connection. The main function of UDP protocol is to compress the data of network communication into the form of datagram. The UDP protocol has no reliability and error checking, but it is fast.

Summary:
IP protocol: IPv4
TCP protocol: transmission control protocol (connection protocol, reliable, slow speed) three-way handshake, four waved hands
UDP protocol: user datagram protocol (no connection protocol, unreliable, fast, such as Internet games generally Use UDP)

Communication diagram:
Insert picture description here

knock off

Thank you for reading~~~
Looking is just an input way of learning. The important thing is understanding, practice and output. Keep the input and output well~~ Otherwise, the input will not be too much, and the output will soon be forgotten ヽ(*.>Д<)o゜

Guess you like

Origin blog.csdn.net/zhangzhanbin/article/details/112547816