Detailed explanation of TCP/IP protocol: Volume 1 Reading Notes-Basics of IP, UDP, and TCP Protocols

Source: Internet
Author: User

IP: Internet Protocol

Unreliable: IP datagram cannot be successfully delivered to the destination, and only the best transmission service is provided.

No connection: the IP address does not maintain any status information about subsequent datagram. The processing of each datagram is independent of each other.


IP Header

The header length of a common IP address is 20 bytes, unless it contains an option field.

Included fields:

4-bit version, 4-bit header length, 8-bit service type, 16-bit total length (bytes), 16-bit logo, 3-bit logo (used for sharding), 13-bit slice offset (used for fragment), 8-bit TTL, 8-bit Protocol (ICMP, IGMP, TCP, UDP, EGP, etc.), 16 header checks,32-bit source IP address and 32-bit destination IP address, Option (if any)


The leftmost is the highest bit, transmitted in the upper-end mode (Network byte order ).


PS: The Ping program uses ICMP echo request packets, and the Traceroute program uses the TTL fields in the ICMP message and IP header.



UDP: User Datagram Protocol

UDP is a simple datagram-oriented transport layer protocol:Each output operation of a process generates a UDP datagram and assembles it into an IP datagram to be sent.. (Unreliable and connectionless)



UDP Header

The size is 8 bytes.


Included Fields:

16-bit source port number and 16-bit destination port number16-bit UDP length, 16-bit UDP check






TCP: Transmission Control Protocol


TCP Service:

TCP provides a connection-oriented and reliable byte stream service.

TCP provides reliability through the following methods:

  • Application Data is divided into data blocks (byte stream service) that TCP considers to be the most suitable for sending ).
  • When TCP sends a segment, it starts a timer and waits for the destination to confirm receipt of the segment. If a confirmation message cannot be received in time, the message segment will be resold.
  • When TCP receives data from the other end of the TCP connection, it sends a confirmation message. This confirmation is not sent immediately, and will usually be postponed by a few seconds ).
  • TCP will keep its header and data validation
  • TCP sorts the received data again, and delivers the received data to the application layer in the correct order.
  • The TCP receiver must discard duplicate data.
  • TCP provides traffic control.


TCP Header

The size is 20 bytes.


Included Fields:

16-bit source port number and 16-bit destination port number,32-bit serial number,32-bit serial number, 4-bit header length, 16-bit window size, 16 checks, 16 Emergency pointers





TCP connection establishment and Termination


Establish connection protocol

1. the requester sends a SYN segment to indicate the port of the server to which the customer intends to connect and the initialization serial number (ISN ). This SYN segment is the packet segment 1.

2. the server sends back the SYN packet segment (packet segment 2) containing the initial server serial number as the response. At the same time, set the serial number to the customer's ISN plus 1 to confirm the customer's SYN packet segment. A syn occupies a sequence number.

3. The customer must set the validation serial number to ISN plus 1 of the server to confirm the SYN packet segment of the server (packet segment 3)

The three packets are connected. This process is also called a three-way handshake (Three-way handshake).





Connection termination protocol (4 white handshakes)

1. When the application is closed, the TCP client sends a FIN to disable data transmission from the customer to the server.

2. When the server receives the FIN, it sends back an ACK and confirms that the serial number is added to 1. At the same time, the TCP server also sends a file terminator to the application.

3. When the server program needs to disable data transmission from the server to the customer, the TCP End of the server will send a FIN.

4. The customer must send a confirmation message to the FIN in 3 and set the confirmation serial number to receive the serial number plus 1.



TCP status change diagram



2MSL waiting status

The TIME_WAIT status is also called the 2MSL wait status. For each specific TCP implementation, You must select a Maximum message Segment life time MSL (Maximum Segment life time ). It is the longest time for any packet segment to be discarded in the network.


Why does the client have to wait for 2MSL in the TIME_WATI status? There are two reasons for this.

First, to ensure that the last ACK packet segment sent by the client can reach the server. This ACK packet segment may be lost, so that the server in the LAST_ACK status cannot receive confirmation of the sent FIN + ACK packet segment. The server will send the FIN + ACK packet segment timeout, and the client will be able to receive the retransmission packet segment within 2MSL.

Second, prevent "invalid connection request packets" from appearing in this connection. After the client sends the last ACK packet segment, it goes through 2MSL, in this way, all the packet segments generated during the duration of the connection can be removed from the network (the service life is MSL ). In this way, the old connection request packet segment will not appear in the next new connection.

For details, see "Computer Network 5th"-edited by Xie xiren


Not complete ......




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.