Bird
Raised Fist0
Interview Prepcomputer-networkseasyAmazonGoogleMicrosoftFlipkartSwiggyRazorpay

TCP Three-Way Handshake - SYN, SYN-ACK, ACK & Connection Teardown

Choose your preparation mode3 modes available
▶
Steps
setup

Initialize / Setup

Initialize client and server nodes in idle state with no packets sent yet. The network link between them is inactive.

💡 Starting with a clean slate helps visualize the entire handshake and teardown process from the beginning.
Line:pass # No code needed for setup
💡 The network is ready but no communication has started yet.
📊
TCP Three-Way Handshake - SYN, SYN-ACK, ACK & Connection Teardown - Watch the Algorithm Execute, Step by Step
Watching each packet flow and state change visually helps you understand the purpose and sequence of TCP handshake and teardown without needing to memorize protocol details.
Step 1/10
·Active fill★Answer cell
Initialized client and server nodes; network links inactive.
Hop: 0
Client
Server
Client sent SYN packet to server to initiate connection.
Hop: 1
Client
Server
📦Packet
↗ fromclient
↘ toserver
🔌 protocolTCP
🚩 flagsSYN
src→client_ip:12345
dst→server_ip:80
flags→SYN
SYN: client→server
Server processed SYN and sent SYN-ACK to client.
Hop: 2
Client
Server
📦Packet
↗ fromserver
↘ toclient
🔌 protocolTCP
🚩 flagsSYN, ACK
src→server_ip:80
dst→client_ip:12345
flags→SYN, ACK
SYN: client→server
SYN-ACK: server→client
Client sent ACK to server, completing handshake.
Hop: 3
Client
Server
📦Packet
↗ fromclient
↘ toserver
🔌 protocolTCP
🚩 flagsACK
src→client_ip:12345
dst→server_ip:80
flags→ACK
SYN: client→server
SYN-ACK: server→client
ACK: client→server
Server received ACK; connection established.
Hop: 4
Client
Server
SYN: client→server
SYN-ACK: server→client
ACK: client→server
Client sent FIN to server to start connection teardown.
Hop: 5
Client
Server
📦Packet
↗ fromclient
↘ toserver
🔌 protocolTCP
🚩 flagsFIN
src→client_ip:12345
dst→server_ip:80
flags→FIN
SYN-ACK: server→client
ACK: client→server
FIN: client→server
Server acknowledged FIN with ACK.
Hop: 6
Client
Server
📦Packet
↗ fromserver
↘ toclient
🔌 protocolTCP
🚩 flagsACK
src→server_ip:80
dst→client_ip:12345
flags→ACK
ACK: client→server
FIN: client→server
ACK: server→client
Server sent FIN to client to complete teardown.
Hop: 7
Client
Server
📦Packet
↗ fromserver
↘ toclient
🔌 protocolTCP
🚩 flagsFIN
src→server_ip:80
dst→client_ip:12345
flags→FIN
FIN: client→server
ACK: server→client
FIN: server→client
Client sent final ACK to server, closing connection.
Hop: 8
Client
Server
📦Packet
↗ fromclient
↘ toserver
🔌 protocolTCP
🚩 flagsACK
src→client_ip:12345
dst→server_ip:80
flags→ACK
ACK: server→client
FIN: server→client
ACK: client→server
Connection fully closed; client and server idle.
Hop: 9
Client
Server
ACK: server→client
FIN: server→client
ACK: client→server

Key Takeaways

✓ The TCP three-way handshake ensures both client and server agree on connection parameters before data transfer.

This handshake is hard to grasp from code alone because it involves asynchronous packet exchanges and state changes.

✓ Connection teardown is a four-step process involving FIN and ACK packets from both sides to close the connection gracefully.

Visualizing the packet flow clarifies why both sides must exchange FIN and ACK packets.

✓ Node states and packet flags clearly indicate the current phase of the connection lifecycle at each step.

Seeing states change from idle to sending and processing helps understand protocol state machines beyond static code.

Practice

(1/5)
1. Trace the sequence of events when a client using HTTP Long Polling requests real-time updates from a server.
easy
A. Client sends a request; server responds with a stream of events over a single connection
B. Client opens a persistent connection; server pushes updates continuously without client requests
C. Client sends a request; server responds immediately with current data; client waits before sending another request
D. Client sends a request; server holds it open until data is available; server responds; client immediately sends a new request

Solution

  1. Step 1: Understand Long Polling mechanics

    Client sends an HTTP request that the server holds open until new data is available.
  2. Step 2: Server response and client behavior

    Once data is sent, the connection closes, and the client immediately sends a new request to wait for further updates.
  3. Step 3: Evaluate other options

    Client opens a persistent connection; server pushes updates continuously without client requests describes WebSocket behavior. Client sends a request; server responds immediately with current data; client waits before sending another request misses the 'hold open' aspect, responding immediately regardless of data availability. Client sends a request; server responds with a stream of events over a single connection describes SSE.
  4. Final Answer:

    Option D -> Option D
  5. Quick Check:

    Long Polling = request held open until data -> response -> new request
Hint: Long Polling = held-open request until data, then reconnect
Common Mistakes:
  • Confusing Long Polling with SSE or WebSocket persistent connections
  • Assuming server pushes data without client requests in Long Polling
  • Believing Long Polling responses are immediate regardless of data
2. Why might DHCP not be suitable for assigning IP addresses in a network with extremely high client churn and very short connection durations?
medium
A. Because the overhead of frequent DHCP Discover and Request messages can cause network congestion
B. Because DHCP cannot assign IP addresses dynamically in such environments
C. Because DHCP servers do not support IP address leasing
D. Because clients must manually configure IP addresses in such cases

Solution

  1. Step 1: Understand DHCP overhead

    Each new client connection triggers the DORA sequence, which adds network traffic.
  2. Step 2: Analyze impact of high churn

    Frequent IP requests can overload the DHCP server and increase broadcast traffic, causing congestion.
  3. Step 3: Evaluate other options

    Because DHCP cannot assign IP addresses dynamically in such environments is false; DHCP is designed for dynamic assignment. Because DHCP servers do not support IP address leasing is incorrect; DHCP supports leasing. Because clients must manually configure IP addresses in such cases is unrelated to DHCP limitations.
  4. Final Answer:

    Option A -> Option A
  5. Quick Check:

    High churn leads to excessive DHCP message overhead.
Hint: High churn -> many DHCP messages -> potential congestion
Common Mistakes:
  • Believing DHCP cannot assign dynamically in such cases
  • Confusing DHCP leasing with static assignment
  • Assuming manual configuration is required when DHCP is unsuitable
3. Which of the following statements about DHCP IP address leasing is INCORRECT?
medium
A. Once a lease expires, the IP address is immediately available for reassignment
B. Clients must renew their lease before it expires to keep the same IP address
C. DHCP servers can reclaim IP addresses from clients that do not renew leases
D. Leases help prevent IP address conflicts in the network

Solution

  1. Step 1: Understand lease expiration behavior

    When a lease expires, the IP address is not immediately available; there is usually a grace period before reassignment to avoid conflicts.
  2. Step 2: Analyze other options

    Options B, C, and D are correct statements about DHCP leasing behavior.
  3. Final Answer:

    Option A -> Option A
  4. Quick Check:

    Immediate reassignment after expiration is incorrect; DHCP uses timers to prevent conflicts.
Hint: Lease expiration ≠ instant IP reuse; timers prevent conflicts
Common Mistakes:
  • Assuming IPs are instantly reusable after lease expiry
  • Confusing lease renewal with release
  • Believing leases do not prevent conflicts
4. Which of the following statements about HTTP 4xx and 5xx status codes is INCORRECT?
medium
A. 4xx status codes indicate client-side errors, meaning the client must modify the request to succeed.
B. 5xx status codes indicate server-side errors, meaning the server failed to fulfill a valid request.
C. A 403 status code means the client is forbidden from accessing the resource, even if authenticated.
D. A 404 status code means the server is temporarily unavailable and the client should retry later.

Solution

  1. Step 1: Review meanings of 4xx and 5xx status codes

    4xx = client errors; 5xx = server errors.
  2. Step 2: Analyze each statement

    4xx status codes indicate client-side errors, meaning the client must modify the request to succeed. is correct: 4xx means client must fix request.
    5xx status codes indicate server-side errors, meaning the server failed to fulfill a valid request. is correct: 5xx means server failed.
    A 404 status code means the server is temporarily unavailable and the client should retry later. is incorrect: 404 means 'Not Found', not temporary unavailability; 503 indicates temporary server unavailability.
    A 403 status code means the client is forbidden from accessing the resource, even if authenticated. is correct: 403 means forbidden access regardless of authentication.
  3. Final Answer:

    Option D -> Option D
  4. Quick Check:

    404 is about missing resource, not server availability.
Hint: 404 = Not Found, 503 = Service Unavailable
Common Mistakes:
  • Confusing 404 with temporary server errors
  • Assuming 403 means unauthenticated rather than forbidden
  • Mixing client and server error categories
5. Which of the following statements about TCP congestion control using AIMD is INCORRECT?
medium
A. AIMD guarantees zero packet loss in all network conditions
B. Multiplicative decrease halves the congestion window upon detecting packet loss
C. Additive increase means the congestion window grows by a fixed amount each RTT
D. AIMD balances efficient bandwidth use with network stability

Solution

  1. Step 1: Verify additive increase meaning

    Congestion window increases by a fixed increment per RTT, which is correct.
  2. Step 2: Confirm multiplicative decrease behavior

    On loss detection, TCP halves the congestion window, consistent with multiplicative decrease.
  3. Step 3: Assess AIMD guarantees

    AIMD does not guarantee zero packet loss; it aims to reduce loss by controlling sending rate.
  4. Step 4: Understand AIMD's balance goal

    AIMD is designed to balance throughput and network stability, which is true.
  5. Final Answer:

    Option A -> Option A
  6. Quick Check:

    AIMD reduces but does not eliminate packet loss.
Hint: AIMD controls congestion but cannot prevent all packet loss.
Common Mistakes:
  • Believing AIMD eliminates all packet loss
  • Misunderstanding additive increase as exponential growth
  • Confusing multiplicative decrease with complete stop
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard