Technology Sharing

[Computer Network] In-depth understanding of the three-way handshake and four-way wave of the TCP protocol 1. Introduction

2024-07-12

한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina


Preface

In computer networks, TCP is a connection-oriented, reliable, byte-stream-based transport layer communication protocol. Its core feature is that it provides reliable data transmission, and this reliability is mainly reflected in the process of connection establishment (three-way handshake) and disconnection (four-way handshake). In this blog, we will explore these two processes in detail.


1. Description

2.1 Diagram

insert image description here

2.2 Three-way handshake

The three-way handshake is the process of establishing a connection in the TCP protocol. The specific steps are as follows:

  • First handshake: The client sends a SYN segment to the server to request to establish a connection. The message contains a client initial sequence number X.

  • Second handshake: After receiving the SYN segment, the server will send a SYN+ACK segment to the client, indicating that it agrees to establish a connection. This segment will contain the server's initial sequence number Y and the confirmation number X+1 of the client's initial sequence number.

  • The third handshake: After receiving the SYN+ACK segment, the client sends an ACK segment to the server to confirm the server's initial sequence number. The confirmation number in this segment is Y+1.

2.3 Four waves

The four waves are the process of TCP protocol disconnection. The specific steps are as follows:

  • First wave: When the client decides to close the connection, it sends a FIN segment to the server, which contains the current sequence number, indicating that the client has no data to send.

  • Second wave: After receiving the FIN segment, the server will send an ACK segment to the client to confirm that it has received the FIN segment. The confirmation number in this segment is the client's sequence number + 1.

  • The third wave: If the server has no data to send, it will send a FIN segment to the client, which will contain the current sequence number.

  • Fourth wave: After receiving the FIN segment, the client will send an ACK segment to the server to confirm that it has received the FIN segment. The confirmation number in this segment is the server's sequence number + 1. Then, the client will wait for a period of time (two maximum segment lifetimes) to ensure that the server has received the ACK segment before actually closing the connection.


2. Conclusion

The three-way handshake and four-way handshake of the TCP protocol are its core features, which ensure the reliability of the TCP connection. Understanding these two processes is very helpful for a deeper understanding of the TCP protocol and the principles of network communication. I hope this blog can help you better understand the working principle of the TCP protocol.