TCP is connection-oriented. In a connection-oriented environment, a connection must be established between two terminals before data transmission begins. The process of establishing a connection ensures that both parties are ready to transmit and receive data before sending application data packets.
Reference address:Establishing a TCP connection: three-way handshake
The two communicating parties must synchronize with each other using the initialization sequence number seq and the acknowledgment number ack from the other party to confirm the successful transmission. (The ack number is the number of the next octet that is expected to be received.) The synchronization signal is usually written as SYN and the acknowledgment signal is ACK. The entire synchronization process is called a three-way handshake.
1) Host A sends SYN to host B: My sequence number seq is X.
2) Host B sends SYN and ACK to host A: My sequence number seq is X+1, and the response number is X+1 (waiting to receive the X+1th octet).
3) Host B sends SYN and ACK to Host B: My sequence number seq is X+1, and the response number is Y+1.
Through the above three steps (three-way handshake), the TCP connection is established and data transmission begins. TCP on any machine can passively wait for handshakes or actively initiate handshakes. Once the connection is established, data can flow in both directions in a peer-to-peer manner.
If TCP uses 1 as the initialization sequence number for each connection, when the local system is restarted, the remote system will think that the previous connection still exists. So each time a connection is made, the host will randomly select an initialization sequence number and use it to identify the position of the transmitted octet in the data stream. Then both parties have to negotiate their respective sequence numbers, because when the receiver receives the first SYN, he does not know whether it is a delayed old signal. So it must request to send this SYN to verify.
In general, TCP uses the least information segment to implement the three-way handshake, which is effective in reducing network communication traffic. In short, the three-way handshake makes both parties ready to transmit data and unifies the initialization sequence number.
Closing a TCP connection: Improved three-way handshake
For an established connection, TCP uses a modified three-way handshake to end the call (using a segment with a FIN additional flag).
1) When the application on host A notifies TCP that the data has been completed, TCP sends a segment with a FIN additional mark to host B (FIN is understood as
finish).
2) After receiving the FIN segment, host B does not immediately reply to host A with a FIN segment, but instead sends an ACK to host A.
At the same time, notify the corresponding application: the other party requests to close the connection (send ACK first to prevent the other party from retransmitting the FIN segment during this period of time).
3) The application on host B tells TCP: I want to completely close the connection, and TCP sends the second FIN segment to host A.
4) After receiving the second FIN segment, host A sends an ACK to host B to indicate that the connection is completely closed.
TCP Reliability
TCP is stream-oriented, that is, data segments are transmitted as a sequence of bytes.
When the connection is established through the three-way handshake, the sequence number is initialized. During the transmission process, TCP continues to use this sequence number to mark each data segment sent. Every time a data segment is sent, the sequence number is increased by 1. The receiving station reassembles the received data segment based on the sequence number. Why do we rely on sequence numbers to reassemble data segments?
For example, on a network with both high-speed links and low-speed links, the data segments on the high-speed link may arrive earlier than those on the low-speed link. In this case, the sequence number must be relied upon to reassemble the data segments. This is one of the functions of the sequence number.
During the transmission process, the role of the confirmation number ACK is to tell the sender which data packets have been successfully received, and the confirmation number will indicate to the sender the sequence number of the next data segment that the receiver expects to receive. This mechanism is called expected confirmation, that is, the confirmation number is equal to the next expected byte.
In TCP/IP networks, there are two phenomena: timeout and retransmission. If a data segment with a certain sequence number is lost during transmission, resulting in the sender not receiving a response for that data segment within a given time interval, the lost data segment will be required to be retransmitted. The data segment will be stored in the sender's buffer until the sender receives a response number, at which point it will release the buffer. This mechanism is called Positive Acknowledgement and Retransmission (PAR), which is a technology used by the communication protocol to ensure credibility.
The second function of the sequence number is to eliminate duplicate packets in the network (synchronous replication). For example, when the network is congested, if the sender has not received the ACK packet of a data segment from the receiver, it may think that the data segment with this sequence number is lost, so it will resend it. This may cause the receiver to receive two data segments with the same sequence number after the network returns to normal. At this time, the receiver will automatically discard the second identical data segment.
The sequence number and acknowledgment number provide an error correction mechanism for TCP, thus improving the reliability of TCP.
Previous article:About arrays as function parameters
Next article:Research on Motor Temperature Monitoring System Based on TMP275
- Popular Resources
- Popular amplifiers
Recommended Content
Latest Microcontroller Articles
He Limin Column
Microcontroller and Embedded Systems Bible
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
MoreSelected Circuit Diagrams
MorePopular Articles
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
MoreDaily News
- Huawei's Strategic Department Director Gai Gang: The cumulative installed base of open source Euler operating system exceeds 10 million sets
- Download from the Internet--ARM Getting Started Notes
- Learn ARM development(22)
- Learn ARM development(21)
- Learn ARM development(20)
- Learn ARM development(19)
- Learn ARM development(14)
- Learn ARM development(15)
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
Guess you like
- Technical Title
- CS83702 single lithium battery 3.7V power supply built-in boost 18W mono class D amplifier IC
- 【Renovation of old things】 Graffiti desk lamp——lugl4313820
- Share the silkscreen search method of TI device models
- Some thoughts on the development of embedded technology
- Uncover the secrets of Shenzhou XII’s journey home!
- Maximize power density with buck-boost charging and USB Type-C PD technology
- MYZR-IMX6-CB336 core board
- [Telink's new generation low power consumption, high performance, multi-protocol wireless kit B91 review] Unboxing + lighting
- Seek guidance from the experts and find routines.