DEV Community

Discussion on: Explain TCP like I'm five

Collapse
 
themikenicholson profile image
Mike Nicholson • Edited

Imagine you ask a friend to read you a long number over the phone. If you wanted to get this done really quickly your friend could just read all the numbers off as fast as possible. This might work, but maybe an ambulance drives by and you don't hear a few numbers, or maybe you can't write all the numbers down fast enough.

Naturally, you're going to ask your friend to read you a few numbers at a time and you'll let them know when they can proceed with the next ones. This sort of an informal implementation of TCP.

To extend the metaphor image the conversation goes like this:

You: Call your friend at his well known phone number
Friend: Answers phone, says hello
This is like the initiation of a TCP connection, instead of phone numbers TCP uses IP addresses and port numbers. Much like our normal phone etiquette, TCP/IP specifies a protocol, a very clear set of rules on how you connect and start the TCP conversation

You: "Ok, what is the first group of numbers?"
Friend: "1234"
You: "Ok, keep going"

This is like a TCP ACK which acknowledges successful receipt of the first bit of information. You just acknowledged you heard your friend and they could now continue transmitting the next chunk of information

Friend: "5678"
You: "Sorry, I missed that, we have a flaky connection. Can you please repeat the second group"
Friend: "5678"
You: Ok, got it, keep going
This was like a TCP retransmission. Something happened and you detected that you missed a bit of information, you ask your friend to repeat it

In this example, your friend is sending a few chunks of information at a time and you're ensuring you clearly receive everything and in the right order. While this might take a little longer than your friend rambling off the number as fast as possible, you're much more likely to correctly receive the number.

Obviously TCP is much more complex and well specified than an informal phone conversation. Computers need much clearer instructions than humans to complete any task. The underlying principles are the same though.

edit: typo's