In my opinion, anyone in networking needs to understand precisely how the TCP 3-way handshake works. The other day, I posted an oddball network joke on my Facebook that went like this.
A TCP packet walks into a bar and says “I want a beer”. The bartender says “you want a beer?” The TCP packet says, yes a beer.
When I saw this, I instantly laughed because I have a warped sense of humor. But I started to wonder, sitting at work, if any of my network admin/engineer friends understood what was happening. So, I randomly went hunting to see if people in the business understood. To my dismay, not a single person I asked, except someone who just graduated from a technical school(I say just, it’s been about six months), knew without hesitation what the underlying tone of the pun was: good job!
So now I feel that I have to explain the TCP 3-way handshake;
At the beginning of every TCP socket connection, something special happens: the TCP 3-way handshake. This is one of those handshakes that only the cool kids know (sorry, UDP, you are not cool enough today), So the 1,000-foot overview of it is like this. The client sends a packet with the Synchronization flag set (known from here on as the SYN Packet). The server gets that packet, Acknowledges it (hereby known as an ACK), and sends back an SYN to the client. This packet is called the SYN/ACK. The client gets the SYN from the server, and at this point, the TCP socket is opened, and the upper layers of the OSI model go to work.
Below is a diagram of how this plays out; this will be from the point of view of someone going to www.bing.com.
For everyone’s enjoyment, from my favorite packet analysis program, Wireshark, here is the process from device to device (sorry about the size. If you click on it, it will be legible, I promise).
So now that we all know what the TCP 3-way handshake is, let’s look at the joke again;
- A TCP packet walks into a bar and says, “I want a beer.” –> This would be the SYN packet; the TCP packet wants to communicate with the bartender.
- The bartender says, “You want a beer?” –> The bartender ACKs the SYN and sends a SYN of his own.
- The TCP packet says, yes, a beer. –> This is the final ACK, and when the bartender gives him his beer, the TCP socket is opened, and he can enjoy it. Responsibly, of course.