前言
常常聽到 TCP Three-Way Handshake,它們是如何運作的呢?
開始之前,先看了解一下, TCP 使用到的 Header Flags
- SYN: Synchronize(Include a seq #)
- ACK: Acknowledgement (確認收到訊息)
- FIN: Finish
- PSH: Push (送訊息)
- URG: Urgent(馬上送訊息)
- RST: Reset (重設連線)
Three-Way Handshake
Client 要開始跟 Server 對話時,
Client | Action | Server |
---|---|---|
Client A | - SYN: Sequence #101 -> | Server B |
Client A | <- **SYN/ACK** - <- (Your) Sequence #102 (你的下次 Seq 是 102) - <- (My) Sequence #508 - |
Server B |
Client A | - ACK -> - (Your) Sequence #509 (你的下次 Seq 是 509) -> - (My) Sequence #102 -> |
Server B |
再來就是 Server 會 PUSH 資料給 Client …
Client 要結束對話時,
Client | Action | Server |
---|---|---|
Client A | - FIN: 我要結束對話 -> | Server B |
Client A | <- **ACK/FIN** - <- OK…Tell App to stop - <- App stopped … I’m done - - |
Server B |
Client A | - ACK -> - OK… -> |
Server B |