A text read relations IP, UDP and TCP three

Internet is actually a set of ideas and protocol architecture composed. Among them, the agreement is a set of well-known rules and standards, if the parties agree to use, then the communication between them will be no obstacles.

A text read relations IP, UDP and TCP three of the article read relations IP, UDP and TCP three

IP: packet data service destination host

Data packets to be transmitted over the Internet, we must comply with the Internet Protocol (IP) standards, different online devices on the Internet has a unique address, the address is just a number, and it is similar to most home mailing address, you need to know the address of a particular family, this address can be sent conventional package, so that the system will be able to stream the article to the destination.

Address of the computer is called an IP address, visit any website is really just your computer requests information from another computer.

If it is a data packet transmitted from the host A to host B, then prior to transmission, it is appended to the IP address information of the host B on the packet, so as to correct addressing during transmission. Additionally, the IP address of the host is also appended to the data packets A itself, this information with host B can return information to the host A. This additional information will be put into a place called the IP header data structure. IP header information at the beginning of the IP data packet contains an IP version, source IP address, destination IP address, the survival time and other information.

A text read relations IP, UDP and TCP three of the article read relations IP, UDP and TCP three

Simplified three UDP network transmission model

UDP: packet data service applications

IP is the underlying protocol, is only responsible for the data packets to other computers, other computer but do not know which program to put the packet is handed over to the browser or to the king of glory? Therefore, based on IP development protocols and applications can deal with the most common is the "user Datagram protocol (user Datagram protocol)", referred to as the UDP.

UDP One of the most important information is the port number, port number, in fact, a number that would like access to the network for each program needs to bind a port number. It will be able to send via UDP port number specified data packets to the specified procedures, so by IP address information to IP packets sent to the specified computer, and UDP port numbers by the data package to the correct procedure. IP header and, as the port number which is loaded into a UDP header, a UDP header of the original packet and then form the new UDP packet. In addition to the header information of UDP destination port, and source port number.

A text read relations IP, UDP and TCP three of the article read relations IP, UDP and TCP three

Simplified four UDP network transmission model

UDP 不能保证数据可靠性,但是传输速度却非常快,所以 UDP 会应用在一些关注速度、但不那么严格要求数据完整性的领域,如在线视频、互动游戏等。

TCP:把数据完整地送达应用程序

对于浏览器请求,或者邮件这类要求数据传输可靠性(reliability)的应用,如果使用 UDP 来传输会存在两个问题:

  • 数据包在传输过程中容易丢失;
  • 大文件会被拆分成很多小的数据包来传输,这些小的数据包会经过不同的路由,并在不同的时间到达接收端,而 UDP 协议并不知道如何组装这些数据包,从而把这些数据包还原成完整的文件。

基于这两个问题,我们引入 TCP 了。TCP(Transmission Control Protocol,传输控制协议)是一种面向连接的、可靠的、基于字节流的传输层通信协议。相对于 UDP,TCP 有下面两个特点:

  • 对于数据包丢失的情况,TCP 提供重传机制;
  • TCP 引入了数据包排序机制,用来保证把乱序的数据包组合成一个完整的文件。

和 UDP 头一样,TCP 头除了包含了目标端口和本机端口号外,还提供了用于排序的序列号,以便接收端通过序号来重排数据包。

A text read relations IP, UDP and TCP three of the article read relations IP, UDP and TCP three

简化的 TCP 网络四层传输模型

下面我们再看下完整的 TCP 连接过程,通过这个过程你可以明白 TCP 是如何保证重传机制和数据包的排序功能的。

A text read relations IP, UDP and TCP three of the article read relations IP, UDP and TCP three

一个TCP连接的生命周期

从上图可以看出,一个完整的 TCP 连接的生命周期包括了建立连接、传输数据、关闭连接三个阶段。

  • 首先,建立连接阶段。这个阶段是通过“三次握手”来建立客户端和服务器之间的连接。TCP 提供面向连接的通信传输。面向连接是指在数据通信开始之前先做好两端之间的准备工作。所谓三次握手,是指在建立一个 TCP 连接时,客户端和服务器总共要发送三个数据包以确认连接的建立。
  • Second, the data transmission phase. At this stage, the receiving end need to verify operation for each data packet, i.e. the receiving terminal after receiving the data packet, the data packet to send confirmations transmitting end. So when the sender sends a packet is not received within a predetermined time feedback from the receiver to the acknowledgment message, it is determined that the packet loss and retransmission mechanism triggers the transmitting side. Similarly, a large file transfer process will be split into many small packets, data packets arrive at the receiving end, the receiving end in the TCP header will follow the sequence number for sorting, to ensure the complete composition data.
  • Finally, the disconnect phase. After the data transfer is completed, it is necessary to terminate the connection, and it comes to the last stage "four wave" to ensure that both sides can be disconnected.

TCP in order to ensure reliability of data transmission, at the expense of speed packet transmission, because "three-way handshake" and "packet checking mechanisms" such as the number of packets during transmission has doubled.

Original from: https://www.toutiao.com/a6775004074036167176/

This article addresses: https://www.linuxprobe.com/ip-tcp-udp.html Editor: Jiang eleven, Auditor: Bao Pang increase

Linux command Daquan: https://www.linuxcool.com/

REVIEW Internet is actually a set of ideas and protocol architecture composed. Among them, the agreement is a set of well-known rules and standards, if the parties agree to use, then the communication between them will be no obstacles.

Guess you like

Origin www.cnblogs.com/probemark/p/12177783.html