Abstract
- We need to a TCP connection before 2 Host can communicate over the Computer Network
- Established with TCP Handshake
Resource intense
More resource is required on both Client and Server because TCP is a Stateful Network Protocol.
TCP connection in browser
TCP Connection Termination
- There are 2 options for closing a TCP Connection
Graceful TCP Connection Termination
- Four-way closure with
FIN
flags
4 events
A -> B
:A
sends aFIN
packet toB
, with its final Sequence Number ofx
.A <- B
:B
ACK and responds toA
with an acknowledgment number ofx+1
, indicating that it has receivedA
’sFIN
packet.A <- B
: Since TCP is bidirectional,B
also sends its own FIN packet toA
, with its final sequence number ofy
.A -> B
:A
ACK and respondsB
with an acknowledgment number ofy+1
, indicating that it has receivedB
’sFIN
packet.For events two and three, both occur from
B
toA
, and the fields used in the TCP packet do not overlap, meaning both events can happen in the same packet.However, these events are usually separated. For example,
A
may initiate the connection termination (step one) after finishing sending its data, butB
may still have data to send. In this case, whenB
receives theFIN
packet, it cannot immediately proceed to step three.B
must finish sending its data before sending its ownFIN
. Meanwhile,A
can still receive data fromB
even after sending itsFIN
packet.
Ungraceful TCP Connection Termination
- One-way closure with
RST
flags. ARST
flag is typically used in scenarios where the connection cannot be continued, either due to unexpected behaviour, errors, or forceful termination by the application
1 event
A <-> B
: Either party can send anRST
. Once sent, the party will forget everything about that TCP Connection, and the party that receives it will also forget everything.The
RST
does not need to be acknowledged!