TCP/IP easy to understand network protocol

I read an article about TCP/IP easy-to-understand network protocol from a blogger last night, and I felt it was written very well, so let’s take a note here. . . .

The simplest understanding: TCP connection-oriented, reliable data transmission, the establishment of a connection requires a three-way handshake, which will cause delay

                        UDP is disconnected, unreliable transmission, UDP is more

I feel that this blogger’s explanation about TCP and UDP is very good: from Beijing to Hangzhou, TCP is equivalent to building a high-speed railway (to establish a connection) and then open to traffic (transmitting data), and UDP is equivalent to sending express. Lost it (transfer data directly)

What is TCP/IP

The TCP/IP protocol suite is a collection of a set of protocols, also called the Internet protocol suite , which implements mutual communication between hosts on the Internet. TCP and IP are only two very very important protocols, so this Internet protocol family is named after TCP and IP. It also includes other protocols such as UDP, ICMP, IGMP, etc.

Network layering

Four layers of Internet protocol family TCP/IP:

éä¿ææç½ç »åè®®ï¼TCP / IPæ¦è¿ ° ï¼

TCP/IP is divided into link layer , network layer , transport layer , and application layer from bottom to top . The lower layer provides capabilities to the upper layer, and the upper layer uses the capabilities of the lower layer to provide higher abstraction.

1. Link layer: also known as the network interface layer, including operating system device drivers and network cards, they deal with the details of the physical interface with the transmission medium (optical fiber, etc.) together.

2. Network layer: It is also the IP layer, which is responsible for processing the transmission of IP datagrams in the network. The IP layer transmits IP datagrams. With the help of routing tables, IP datagrams are transmitted from one end of the network to the other end, in short , IP implements packet routing and transmission, and IP protocols and routers work at the network layer.

3. The transport layer provides end-to-end communication, including connection-oriented and reliable TCP, and unreliable UDP. It seems that TCP is better, but it is not the case. UDP is faster and more widely used because it does not require the overhead of establishing a connection.

4. Application layer : It is application-related. Different applications solve different problems and require different application protocol layers.

éä¿ææç½ç »åè®®ï¼TCP / IPæ¦è¿ ° ï¼

The link layer deals with the transmission of data on the medium, as well as the details of the host's dealings with the network card, light, etc. Because it is related to the hardware, it needs to rely on the driver of the system. The link layer protocol defines these details, such as how to send data from the network card to the optical fiber, and what format encoding is used. It solves the problem of data flow on the medium.

The link layer function alone is definitely not enough. There are thousands of machines on the network, and host A and B communicate, and you can’t send data to host C. So imitating reality, you need to assign network addresses to hosts through IP addresses. To identify a host in the network and send a data packet, it needs to be correctly routed to the destination. This is like how you travel from home to your company. You need a map. The routing table is similar to this map. IP solves the problem of routing of data packets in the network.

With the network layer, there is transmission routing capability. Because IP packets may lose packets during transmission, this is unreliable. If reliable transmission capabilities are required, the transport layer needs to be based on the IP layer to provide more capabilities. TCP solves the reliability problem. Specifically, if the packet is lost, the TCP layer will be responsible for timeout retransmission. It guarantees reliable transmission through reception confirmation and retransmission mechanisms . But sometimes it is not necessary to guarantee reliability and sequence, which is provided by UDP.

Further up, there are application layer protocols, such as Http, or game server custom protocols. Application layer protocols are usually based on TCP or UDP for transmission.

1. TCP and UDP are the two main transport layer protocols.

2. IP is the main protocol of the network layer. Both TCP and UDP need to be transmitted using IP protocol.

3. ICMP is the Internet Protocol Control Message Protocol, which is a subsidiary protocol of IP. The IP layer uses it to exchange error messages and other important information with other hosts or routers. For example, when a Packet passes through a certain router node, if it exceeds the network's limit on Packet length without fragmentation, it will send an ICMP packet to the sender to report error information. ICMP is used to assist IP to complete packet transmission. .

4. IGMP is an Internet group management protocol, used to multicast a packet to multiple hosts.

5. ARP (Address Resolution Protocol) and RARP (Reverse Address Resolution Protocol) are used to convert addresses between the IP layer and the link layer. The IP layer uses IP addresses and the link layer uses Mac addresses.

 

Package

When sending data, the sender adds some control information to the original data according to the protocol format, and packs it into a process that can correctly transmit data packets on the network called encapsulation.

The TCP/IP protocol suite is encapsulated layer by layer. From the application layer to the link layer, some additional information (header and tail) is added for each layer.

  1. The user data is added to the application header through the application program and transferred to the TCP layer for processing
  2. After the TCP layer is added with the TCP header, a TCP segment (segment) is generated
  3. The TCP segment passes through the IP layer and adds the IP header to generate IP datagrams
  4. IP datagram passes through the link layer and is processed by the Ethernet driver, plus the Ethernet header + tail to generate an Ethernet frame. The length of the Ethernet frame is between 46 and 1500

 

address

Each interface on the Internet has a unique network address, also called IP address. There are two versions of IP address, IPv4 and IPv6. IPv4 is a 32-bit 4-byte integer, and the value range of each byte (8bit) is 0~255, so the 4-byte IPv4 can be represented by four dotted byte values, such as 140.252.13.88. Each decimal value corresponds to each byte in a 32-bit integer. This representation is called dotted decimal. Notation, obviously, it is easy to convert between dotted decimal notation and int32 notation.

IPv4 addresses are divided into five types of ABCDE. The numerical space represented by 32-bit addresses is limited. It is difficult to assign independent IP addresses to all networked devices on the Internet. Therefore, there are dynamic allocation, sharing, public network + intranet address translation (NAT), etc. The problem is essentially to solve the problem of insufficient IP addresses .

IPv6 uses 128bit, and the 128th power of 2 is very large. It claims to be able to assign an IP address to every grain of sand on the earth.

IP datagrams (network layer) use IP addresses, while Ethernet frames (link layer) use hardware (48-bit Mac) addresses. ARP and RARP are used for mapping (conversion) between IP addresses and hardware addresses.

 

port

TCP/UDP uses a 16-bit port number to identify (differentiate) applications . For example, host A sends an IP packet to host B. After host B's kernel receives the IP packet, which application should be handed over to it for processing? The port number is used for this, the kernel will maintain the correspondence between the port number and the application.

More commonly used application layer protocols have agreed port numbers, which are well-known port numbers. Port numbers between 1024 and 5000 are allocated to TCP/IP temporarily, and those greater than 5000 are used for other purposes. In other words, if you use TCP to connect to the network server, the local port number allocated for the socket will be between 1024 and 5000, depending on the port allocation strategy of the operating system.

Domain Name System

The Domain Name System (DNS) provides the conversion between host name and IP address. For example, www.baidu.com is a domain name. Applications can obtain the IP address of a host with a given name through a standard library function (gethostbyname), standard library function (Gethostbyaddr) to achieve the reverse operation.

The ip address is a string of numbers, the meaning is unclear, and it is not easy to remember. The meaning of the host name is clearer , and you can easily remember www.baidu.com. This is why the host name is needed for the existence of an IP address.

Guess you like

Origin blog.csdn.net/zl1107604962/article/details/90637023