DEV Community

Ben Halpern
Ben Halpern Subscriber

Posted on

Explain TCP like I'm five

I understand Transmission Control Protocol (TCP) on some levels, but I feel like I never learned the concepts all that concretely. Can someone give me a really good overview?

Latest comments (37)

Collapse
 
abdul_aziz_6a1f55b8cd5b6c profile image
Abdul Aziz

l Love you

Collapse
 
notriddle profile image
Michael "notriddle" Howell

I just got a message in a bottle. It says something like: I would like to tell you about my troubles, but there's not room enough in this one bottle. I can receive this downstream from you, so please let me know if you got this. [it also says this is the distressed prisoner's first message]

I reply with: I got your bottle, and would like to help you. [I also mentioned that this is my first message]

The prisoner replies with: Thank you, I got your first message. [it is marked as the distressed prisoner's second message]

I also started receiving a bunch of other stuff: I got a bottle with a picture in it [marked as the prisoner's fourth message], a bottle saying "the following bottle contains a picture of where I am" [marked as the prisoner's third message], a bottle with my sister's name on it instead of the prisoner I'm trying to help [so I know it's unrelated], and a bottle with another picture in it [marked as the prisoner's sixth message].

After awhile, I dropped in another bottle, asking the prisoner to resend the fifth message [and marked it as my second message]. After a month of not getting a response, I eventually gave up.

Collapse
 
asknbid profile image
¥§¥Stephan Froede¥§¥

TCP:

You need to ask mom and dad to get a toy. And only if you pay for the toy, and mom and dad do agree, you will get the toy.

UDP
Somebody is gifting you a toy.

Conclusion:
5 year olds love UDP

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

Collapse
 
bgadrian profile image
Adrian B.G.

A group of kids are trying to talk into the school yard.
They need a technology so simple that would allow communication even if one kid left the circle. They were already talking into tin cans, so they invented the strings (TCP).

On a serious note, a good history lesson on why and how HTTP and TCP/IP was created Jeremy Keith

Collapse
 
tmr232 profile image
Tamir Bahar

TCP is all fun and games until you start doing SACK (Selective ACK).

I am going to start handing you boxes. The boxes are numbered.
Your role is to drop the boxes into a hole in ground in order, based in the numbering.
When I give you a box, you read the number back to me.
If you are missing a number (I didn't give you that box, but I gave you a later one), tell me which is the one I gave you, and which is missing.
Keep doing that for arbitrarily many boxes.
If the boxes get too heavy, or if you feel it is a good idea, you can throw away the out-of-order boxes, and tell me which ones you kept.
I will try and only hand you boxes that you need, but I might send you duplicates now and then if you did not reply fast enough.

Collapse
 
rapidnerd profile image
George

General TCP

You like candy
Your friend likes candy
You ask your friend if you can have the candy
If the candy you have is the same candy that your friend likes you give him some of the candy
If hes greedy he takes all of the candy

UDP
The candy is actually a carrot

Collapse
 
mitchwongho profile image
Mitchell Wong Ho

Julia Evans created a good comic to explain twitter.com/b0rk/status/8022561852...

Collapse
 
owenandrews_ profile image
Owen Andrews

I could tell you a joke about UDP but you might not get it.

Collapse
 
anthonylavado profile image
Anthony Lavado

Telling this joke in an interview is what got me my current job.

Collapse
 
ben profile image
Ben Halpern • Edited

Collapse
 
daveblythe profile image
Dave Blythe (he/him)

Really, Ben? THIS is the one that bothered you, lol?

Collapse
 
dennisfen profile image
Denis Borisevich • Edited

Not an overview but for the sake of completeness this old joke must be on this thread:)

Hello, would you like to hear a TCP joke?
Yes, I'd like to hear a TCP joke.
OK, I'll tell you a TCP joke.
OK, I'll hear a TCP joke.
Are you ready to hear a TCP joke?
Yes, I am ready to hear a TCP joke.
OK, I'm about to send the TCP joke. It will last 10 seconds, it has two characters, it does not have a setting, it ends with a punchline.
OK, I'm ready to hear the TCP joke that will last 10 seconds, has two characters, does not have a setting and will end with a punchline.
I'm sorry, your connection has timed out...
...Hello, would you like to hear a TCP joke?