乐闻世界logo
搜索文章和话题

What is the process and principle of TCP three-way handshake?

2月21日 17:10

TCP Three-Way Handshake Explained

The TCP three-way handshake is a critical process for establishing reliable connections, ensuring both parties are ready for data transmission.

Handshake Process

  1. First Handshake (SYN): Client sends a segment with SYN=1, seq=x, enters SYN_SENT state, waits for server confirmation
  2. Second Handshake (SYN+ACK): Server receives SYN, sends segment with SYN=1, ACK=1, seq=y, ack=x+1, enters SYN_RCVD state
  3. Third Handshake (ACK): Client receives SYN+ACK, sends segment with ACK=1, seq=x+1, ack=y+1, both parties enter ESTABLISHED state

Why Three-Way Handshake is Necessary

  • Prevent invalid connection requests from suddenly reaching the server: If it were two-way handshake, an expired connection request from client reaching server would cause server to mistakenly treat it as a new connection, wasting resources
  • Synchronize initial sequence numbers of both parties: Three-way handshake ensures both parties know each other's initial sequence numbers, laying foundation for reliable transmission
  • Confirm both parties' receive and send capabilities: Through three interactions, both parties can confirm each other's send/receive functions are normal
  • What happens if the third handshake is lost during the three-way handshake?
  • How does SYN Flood attack exploit the three-way handshake? How to defend against it?
  • Why not two-way handshake or four-way handshake?
标签:TCP