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.
insert
Client Sends SYN to Server
Client sends a SYN packet to initiate connection. Client state changes to sending, server remains idle. The edge from client to server becomes active with data flowing.
💡 The SYN packet signals the start of the TCP handshake, requesting to open a connection.
Line:# Client sends SYN packet
💡 The handshake begins with the client requesting connection establishment.
processing
Server Receives SYN and Sends SYN-ACK
Server receives the SYN packet and processes it. Server state changes to processing, then sends a SYN-ACK packet back to client. The edge from server to client becomes active with data flowing.
💡 Server acknowledges the client's request and responds with SYN-ACK to continue handshake.
Line:# Server receives SYN and sends SYN-ACK
💡 The handshake requires mutual agreement; server confirms receipt and readiness.
processing
Client Receives SYN-ACK and Sends ACK
Client receives the SYN-ACK packet, processes it, and sends an ACK packet back to server to complete handshake. Client state changes to sending, edge from client to server becomes active.
💡 Client confirms connection establishment by sending ACK, completing the three-way handshake.
Line:# Client receives SYN-ACK and sends ACK
💡 The handshake completes only after client acknowledges server's response.
processing
Server Receives ACK - Connection Established
Server receives the ACK packet, processes it, and changes state to done. Both client and server are now connected and idle, ready for data transfer.
💡 Receiving the final ACK confirms the connection is established and ready for communication.
Line:# Server receives ACK and finalizes connection
💡 The handshake is a three-step process ensuring both sides agree on connection parameters.
insert
Client Initiates Connection Teardown with FIN
Client sends a FIN packet to server to initiate connection teardown. Client state changes to sending, edge from client to server becomes active with data flowing.
💡 FIN packet signals the client wants to close the connection gracefully.
Line:# Client sends FIN to start teardown
💡 Connection teardown is a controlled process initiated by one side.
processing
Server Receives FIN and Sends ACK
Server receives the FIN packet, processes it, and sends an ACK packet back to client to acknowledge the teardown request. Server state changes to sending, edge from server to client becomes active.
💡 Server acknowledges the client's request to close the connection.
Line:# Server receives FIN and sends ACK
💡 Acknowledging FIN ensures both sides agree on connection closure.
insert
Server Sends FIN to Client
Server sends its own FIN packet to client to complete teardown from its side. Server state remains sending, edge from server to client remains active.
💡 Server signals it is also ready to close the connection.
Line:# Server sends FIN to client
💡 Both sides must exchange FIN packets to fully close the connection.
processing
Client Receives FIN and Sends Final ACK
Client receives the server's FIN packet, processes it, and sends the final ACK packet back to server. Client state changes to sending, edge from client to server becomes active.
💡 The final ACK completes the four-way connection teardown handshake.
done
Connection Fully Closed
Both client and server have completed the teardown handshake and are now idle with no active packets or data flowing. The connection is fully closed.
💡 The connection teardown is complete, freeing resources on both sides.
Line:pass # No code needed for final state
💡 TCP connection lifecycle ends with a four-step handshake for teardown.
def tcp_handshake_and_teardown():
# STEP 1: Initialize nodes
pass # Setup done visually
# STEP 2: Client sends SYN
# send_packet(client, server, flags=['SYN'])
# STEP 3: Server receives SYN and sends SYN-ACK
# receive_packet(server)
# send_packet(server, client, flags=['SYN', 'ACK'])
# STEP 4: Client receives SYN-ACK and sends ACK
# receive_packet(client)
# send_packet(client, server, flags=['ACK'])
# STEP 5: Server receives ACK - connection established
# receive_packet(server)
# STEP 6: Client sends FIN to start teardown
# send_packet(client, server, flags=['FIN'])
# STEP 7: Server receives FIN and sends ACK
# receive_packet(server)
# send_packet(server, client, flags=['ACK'])
# STEP 8: Server sends FIN
# send_packet(server, client, flags=['FIN'])
# STEP 9: Client receives FIN and sends final ACK
# receive_packet(client)
# send_packet(client, server, flags=['ACK'])
# STEP 10: Connection closed
pass # Final state visually represented
📊
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
Step 1: Understand Long Polling mechanics
Client sends an HTTP request that the server holds open until new data is available.
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.
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.
Final Answer:
Option D -> Option D
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
Step 1: Understand DHCP overhead
Each new client connection triggers the DORA sequence, which adds network traffic.
Step 2: Analyze impact of high churn
Frequent IP requests can overload the DHCP server and increase broadcast traffic, causing congestion.
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.
Final Answer:
Option A -> Option A
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
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.
Step 2: Analyze other options
Options B, C, and D are correct statements about DHCP leasing behavior.
Final Answer:
Option A -> Option A
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
Step 1: Review meanings of 4xx and 5xx status codes
4xx = client errors; 5xx = server errors.
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.
Final Answer:
Option D -> Option D
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
Step 1: Verify additive increase meaning
Congestion window increases by a fixed increment per RTT, which is correct.
Step 2: Confirm multiplicative decrease behavior
On loss detection, TCP halves the congestion window, consistent with multiplicative decrease.
Step 3: Assess AIMD guarantees
AIMD does not guarantee zero packet loss; it aims to reduce loss by controlling sending rate.
Step 4: Understand AIMD's balance goal
AIMD is designed to balance throughput and network stability, which is true.
Final Answer:
Option A -> Option A
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 unknownstrongwhile earning +1 Grip toward your certificate.