DEV Community

Marvin Kome
Marvin Kome

Posted on

My understanding of TCP three way handshake

I recently did a dive on TCP and got to understand a bit about the three way handshake. In an attempt to solidify my knowledge I'm writing an article on what I learnt. So let's get started.

What's the Three way handshake?

Well, for starters the three way handshake is simply a way for both the client and server to acknowledge that they're both communicating on the right socket. It is also used to initiate, negotiate and separate TCP sockets connections at the same time.

How does it work?

So the journey of the three way handshake starts from the client. The client sends a packet to the server

SYN: A
Where A is any random number

This basically means "Hey server synchronize with my random number A" which also means "Hey server all my messages will start with A"

Then the server ACKnowledge the client's synchronization, and then sends its own synchronization number

ACK: A+1; SYN: B
Where B is also any random number

That basically means "Hey client I'm acknowledging your Syn number, Also all my messages will start with B".

Then finally the client responds with

ACK: B+1

Which basically means "Hey server, I'm acknowledging your syn number too. Cheers".

Additional resources

Here are additional resources to questions I had about the three way handshake.

Why do we need a 3 way handshake
https://pcarleton.com/2018/06/06/why-does-tcp-need-a-3-way-handshake-anyway/

Why does the ACK bumb the number by 1
https://stackoverflow.com/questions/6804979/why-does-tcps-three-way-handshake-bump-the-sequence-number-when-acking

Why not just use 2 way handshake
https://networkengineering.stackexchange.com/questions/24068/why-do-we-need-a-3-way-handshake-why-not-just-2-way

Thanks for reading this far. That's my basic understanding of the three way handshake.

Thanks again ;)

Top comments (0)