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
FINflags
4 events
A -> B:Asends aFINpacket toB, with its final Sequence Number ofx.A <- B:BACK and responds toAwith an acknowledgment number ofx+1, indicating that it has receivedA’sFINpacket.A <- B: Since TCP is bidirectional,Balso sends its own FIN packet toA, with its final sequence number ofy.A -> B:AACK and respondsBwith an acknowledgment number ofy+1, indicating that it has receivedB’sFINpacket.For events two and three, both occur from
BtoA, 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,
Amay initiate the connection termination (step one) after finishing sending its data, butBmay still have data to send. In this case, whenBreceives theFINpacket, it cannot immediately proceed to step three.Bmust finish sending its data before sending its ownFIN. Meanwhile,Acan still receive data fromBeven after sending itsFINpacket.
Ungraceful TCP Connection Termination
- One-way closure with
RSTflags. ARSTflag 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
RSTdoes not need to be acknowledged!
