Understanding TCP/IP Protocols: A Clear Overview

Understanding TCP/IP Protocols: A Clear Overview

Author: MobMsg, a Senior Full-Stack Engineer and Partner at the Architect Community!

TCP/IP Protocol Family

The core protocol of the Internet is TCP/IP, widely used in local area networks and wide area networks, with a development history of over 20 years, and is the current international standard. TCP/IP is a protocol family that includes various protocols, network models, and layers as shown in the figure.

Understanding TCP/IP Protocols: A Clear Overview

The complete family portrait of TCP/IP protocols.

Five-Layer Network Model of TCP/IP

Application Layer: Applications send and receive data after interconnecting networks through TCP/IP. They select the required service type, organize data according to the transport layer requirements, and pass down either message sequences or byte streams.

Transport Layer: Provides communication services between application layers, also known as end-to-end communication. It offers reliable data transmission services, ensuring that data is accurately and orderly delivered to its destination. After data is sent, confirmation information must be returned by the recipient; any lost data must be retransmitted by the sender. The object of transmission is transport layer packets.

Internet Layer: Also known as IP Layer, it is responsible for communication between machines. After receiving a request from the transport layer, it transmits information packets to the destination. This packet is encapsulated in an IP datagram, and the routing algorithm decides whether to send it directly to the destination or to a router, then passes the data down to the network interface layer. Upon receiving the datagram, it checks for correctness, and the routing algorithm determines whether to process locally or forward it. If the destination belongs to the local network, it strips the header from the datagram and selects an appropriate transport layer protocol to pass the packet up.

Network Interface Layer: Also known as Data Link Layer, it is located below the TCP/IP protocol layer and is responsible for receiving IP datagrams and sending them out through the selected network.

Hardware Layer: Handles the hardware part that connects to the network. This includes the operating system control, device drivers for hardware, NIC (Network Interface Card), fiber optics, and all physical visible parts (including connectors and all transmission media).

Responsibilities of TCP/IP Protocols

Understanding TCP/IP Protocols: A Clear Overview

Application Layer Protocol Functions

TCP Protocol Data Transmission Process

The Transmission Control Protocol (TCP) is the transport layer protocol of the Internet that provides connection-oriented reliable transmission services, with reliability ensured by retransmission techniques. The TCP header size must be a multiple of 4 bytes, with a fixed header size of 20 bytes that remains unchanged.

Understanding TCP/IP Protocols: A Clear Overview

Diagram of TCP data packets.

ACK: Acknowledgment bit, when its value is 1, the acknowledgment number is valid. SYN: Synchronization request, used when the two parties in a TCP connection negotiate the initial sequence number. RST: Reset, occurs when there is an anomaly in data transmission in the TCP connection, requiring a resend. FIN: After communication ends, when its value is 1, the connection is torn down.

TCP Three-Way Handshake to Establish Connection

First handshake: When establishing a connection, the client sends a SYN packet (syn=i) to the server and enters the SYN_SEND state, waiting for server confirmation. SYN stands for Synchronize Sequence Numbers.

Second handshake: The server receives the SYN packet and must confirm the client’s SYN (ack=i+1) while also sending its own SYN packet (seq=j), which is the SYN+ACK packet. At this point, the server enters the SYN_RECV state.

Third handshake: The client, upon receiving the server’s SYN+ACK packet, sends a confirmation packet ACK(j+1) to the server. After this packet is sent, both the client and server enter the ESTABLISHED state, completing the three-way handshake.

Understanding TCP/IP Protocols: A Clear Overview

Diagram of the three-way handshake establishing a connection.

Normal Data Transmission Process of TCP

This diagram represents the process of transmitting two data packets. Host A sends the first N bytes of data to Host B, with SEQ=i. After Host B receives it, it must immediately send a confirmation ACK packet back to Host A, with ACK=i+N+1, so that Host A can confirm the successful transmission of the data. During the transmission of the second packet, the SEQ value is R, and Host B immediately returns ACK, with ACK=R+N+1. The data packet transmission process continues this way, and it is important to note that the sender only clears the data from the buffer after receiving the acknowledgment packet from the recipient.

ACK acknowledgment bit = SEQ data number + transmitted byte count N + 1. The SEQ number of the first byte is randomly generated locally, and the purpose of SEQ+N is to allow Host A to confirm whether all data sent to Host B has been received or if any has been lost.

Understanding TCP/IP Protocols: A Clear Overview

Diagram of normal data transmission.

TCP Data Retransmission and Fast Retransmission

  • Data Retransmission: Host A transmits data to Host B, but an error occurs in between, and Host B fails to receive it. After some time, if Host A does not receive an ACK confirmation packet from Host B, it retransmits the data packet. Host A starts a timer every time it sends data; if no response packet is received within the specified time, it initiates retransmission.

  • Fast Retransmission: Retransmission occurs after a timeout, but when Host A receives more than three duplicate ACKs, it indicates that data has been lost and requires retransmission. At this time, the retransmission timer has not expired, hence it is called fast retransmission.

Understanding TCP/IP Protocols: A Clear Overview

Diagram of data retransmission.

TCP Four-Way Handshake to End Connection

First handshake: The client sends a FIN to close the data transmission from the client to the server, entering the FIN_WAIT_1 state.

Second handshake: The server receives the FIN and sends an ACK to the client, confirming the sequence number as the received number + 1 (similar to SYN, one FIN occupies one sequence number). The server enters the CLOSE_WAIT state.

Third handshake: The server sends a FIN to close the data transmission from the server to the client, entering the LAST_ACK state.

Fourth handshake: After the client receives the FIN, it enters the TIME_WAIT state and then sends an ACK to the server, confirming the sequence number as the received number + 1. The server enters the CLOSED state, completing the four-way handshake.

Understanding TCP/IP Protocols: A Clear Overview

Diagram of the four-way handshake ending the connection.

TCP Sliding Window and Congestion Control

IP Protocol Data Transmission Process

The Internet Protocol (IP) is generally considered to provide connectionless and unreliable services. However, under good network performance, the data transmitted by IP can arrive at its destination intact.

Connectionless means that data is sent without confirming whether the target system is ready to receive data. Unreliable means that the destination system does not confirm the successful completion of received packets.

Understanding TCP/IP Protocols: A Clear Overview

Diagram of IP datagrams.

IP Sending Data

When sending data, the IP protocol on the source computer must determine whether the destination is on the same network. If the destination is on the same network, direct communication is used; if not, communication must be completed through a gateway or router:

Host A assembles the destination IP address for Host B’s datagram, then performs routing selection, and sends the datagram to the default router (determined by ARP address resolution, obtaining the mapping relationship between the next default router’s IP address and MAC address, then forming a frame with the MAC address as the destination address and encapsulating the IP datagram in the frame’s data area, finally transmitting the datagram through the specific physical network (Ethernet)).

IP Forwarding Data

After the router receives the data frame from Host A, it removes the frame header and processes it. If the destination of this datagram is not local, it needs to be forwarded, determined by the routing algorithm and the local routing table to find the next hop router’s address. After determining the mapping relationship of the next hop router’s IP address and MAC address through ARP address resolution, the MAC address is used as the destination of the data frame, encapsulating the datagram as a data frame, and forwarding the data through Ethernet. This step is repeated until the Nth router is directly connected to the destination, determining the mapping relationship of the destination host’s IP address and MAC address through ARP address resolution, using that MAC address as the frame’s destination address, encapsulating the IP datagram into the frame, and transmitting the data through Ethernet.

IP Receiving Data

Host B receives the data frame, unwraps it, and processes it. After confirming that it is the destination address, it hands the encapsulated data in the datagram to the upper-layer protocol for processing, and then processes it layer by layer until it reaches the application layer, completing the communication.

Five Important Characteristics of TCP/IP

Logical Addressing: Ensures that computers can be located through IP address + host ID.

Routing Selection: Ensures that data packets reach their destination through network path selection protocols.

Domain Name Resolution: Maps domain names to IP addresses, using domain names for ease of memory, and because domain names are relatively fixed and unchanging.

Error Detection: Ensures the reliability of packet-switched transmission, confirming that data is received normally.

Flow Control: Monitors network traffic to prevent network congestion.

Long press to subscribe for more exciting content ▼

Understanding TCP/IP Protocols: A Clear Overview

If you found this helpful, please give it a thumbs up, thank you sincerely!Understanding TCP/IP Protocols: A Clear Overview

Leave a Comment