table of Contents
1. Transport layer protocol
2. TCP
- The concept of TCP
- TCP header
- TCP port number
- TCP connection establishment process
- TCP transmission process
- TCP flow control
- TCP closes the connection
3. UDP
- UDP concept
- UDP header
- UDP transmission process
One. Transport layer protocol
The transport layer defines end-to-end connectivity between host applications. The two most common protocols in the transport layer are Transmission Control Protocol (TCP) and User Datagram Protocol (UDP).
- TCP is connection-oriented and reliable transmission
- UDP is connectionless and unreliable transmission
two. TCP
1. The concept of TCP
TCP is a connection-oriented transport layer protocol that provides reliable transmission services.
2. TCP header
- Source Port: source port number
- Destination Port: destination port number
- Sequence Number: Sequence number
- Acknowledge Number: Confirm the serial number
- Header length: Header length
- Flag:
FIN: release link
SYN: establish link
ACK: confirm link - Checksum: Checksum
3. TCP port number
The port number is used to distinguish different network services. (0-1023 is a well-known port number)
4. The process of TCP connection establishment
TCP three-way handshake to establish a reliable connection
Why do we need three handshake?
As shown in the figure, for example, after sending a SYN, host A encounters a network failure when sending a data packet, and the data packet stays at host A. When the network is suddenly connected, the packet is successfully sent again. When server A receives the data packet, it will confirm and reserve a part of the resources for host A, but the data packet has expired. Host A does not need these resources, so it will cause waste of resources. So need to confirm again (send ACK again).
5. TCP transmission process
The reliable transmission of TCP is also reflected in the fact that TCP uses confirmation technology to ensure that the destination device receives the data from the source device and is accurate.
The working principle of the confirmation technology is as follows: When the
destination device receives the data segment sent by the source device, it sends a confirmation message to the source. After receiving the confirmation message, the source device continues to send the data segment, and so on.
As shown in the figure, host A sends TCP data segments to server A. For the convenience of description, it is assumed that each data segment is 500 bytes in length. When the server A successfully receives the byte whose serial number is M + 1499 and all previous bytes, it will confirm with the serial number M + 1499 + 1 = M + 1500. In addition, because the transmission of the data segment N + 3 fails, the server A fails to receive the bytes with the sequence number M + 1500, so the server A will confirm again with the sequence number M + 1500.
6. TCP flow control
Sliding window mechanism: adjust the sending rate between the server and the host
7. TCP closes the connection
TCP waved four times to close the connection
three. UDP
1. UDP concept
UDP is a connection-free transport layer protocol, and transmission reliability is not guaranteed.
2. UDP header
The UDP header only occupies 8 bytes, and there is no confirmation mechanism when transmitting data.
3. UDP transmission process
When using UDP to transmit data, the application program provides functions such as message arrival confirmation, sequencing, and flow control as needed.
- UDP does not provide a retransmission mechanism, occupies less resources, and has high processing efficiency.
- Some delay-sensitive traffic, such as voice and video, usually use UDP as the transport layer protocol.