2

Explain TCP like I'm five

 3 years ago
source link: https://dev.to/ben/explain-tcp-like-im-five
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Explain TCP like I'm five

Jul 25, 2017

・1 min read

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?

Discussion (39)

pic

CollapseExpand

You and a friend need to share a toy:

  1. You ask a friend if he can play with the toy.

  2. Your friend asks you if you actually asked him for the toy.

  3. You tell your friend that you asked for that toy.

  4. He gives you the toy.

  1. Your friend throws a toy at you and walks away.

Comment button Reply

CollapseExpand

The UDP example has me DYING. That's hilarious

Comment button Reply

CollapseExpand
CollapseExpand

Maybe a more accurate description will be:
Your friend throws a toy at your direction thinking that it will hit you eventually and walks away.

Comment button Reply

CollapseExpand

You're explaining it to a five year old. The less nuance the better.

Comment button Reply

CollapseExpand

I have a five year old. There is nothing beyond this that should be added. You're fantastic. Do you have a five year old? Because this is spot on.

Comment button Reply

CollapseExpand

I don't, mostly for the reason above. :)

Thread

Thread

CollapseExpand

RakNet:

  1. Your friend keeps throwing the letter at you until you explicitly say that you got the letter.

Comment button Reply

CollapseExpand

Well, maybe it's your friend. And it's probably s ball.

Comment button Reply

CollapseExpand

CollapseExpand

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?

Comment button Reply

CollapseExpand

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

Comment button Reply

CollapseExpand

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

Comment button Reply

CollapseExpand

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

Comment button Reply

CollapseExpand

CollapseExpand

I took networking in college, and then a bunch of us went to a coffee shop with free refills, so I always demonstrate network packets with sugar packets.

Let us contrast it with UDP. Imagine you're behind me and ask for a sugar packet. I grab one and throw it over my shoulder. It's not my responsibility to throw it to you, and I don't care if you get it. If you're where I think you are, you can ask for more and more, getting enough sugar to sweeten everyone's coffee, which is why UDP is often used for video, but dropped sugar stays dropped.

TCP has the "three-way handshake", which is more like:

I would like a sugar packet

I heard you ask for a sugar packet

I did ask for a sugar packet

Here's the sugar

This way, the sugar packets don't end up all over the floor.

Comment button Reply

CollapseExpand

So how much sugar do I get to ask for in the first trip to the counter and each subsequent trip, and why is this so?

Comment button Reply

CollapseExpand

you ask for sugar and the server starts a session where he sends a numbered sugar sachets (TCP frames) and you confirm the delivery of each sachet (based on checksums) and as @gldraphael said the sugar arrives after the handshake

Thread

Thread

And if I understand correctly, the barista will give give me one packet on the first trip, then two, then four, etc. and in data terms, each packet is about 14k in size.

Comment button Reply

CollapseExpand

If sugar is the data, shouldn't it be handed over after the three way handshake?

Comment button Reply

CollapseExpand

Is TCP British? It sounds like one from the conversation flow.

Comment button Reply

CollapseExpand

I think additionally I could try and expand on this.

TCP is built on

Network Layer connection = how are we physically transporting this sugar
Internet Layer = Who is exchanging this sugar
Transport Layer = Which cup is this sugar going to

Network layer = responsible for physically transporting this data which is (e.g)
someone walking over or even throwing over the sugar to the person that is requesting it.
This can come in many forms such as ethernet or wifi(simplified). Are you throwing the sugar or are you physically walking there.

Internet Layer = You need to know where these packages are going, These layers usually have frames that contain destination IP and source IPs.
The source IP would be where the packet or sugar is coming from(which person) and where the packet should go destination IP(where the sugar is going)
This would be from a host to host level, we do not know which of the cups the sugar is going into

Transport Layer = Imagine the person asking for the sugar has got three cups. We need to know which cup the sugar is going into. for this purpose we describe the cups as having their port addresses.
Putting the sugar into the designated cup would be transporting from an process to process level transportation.

Transport layer will have different methods of transporting the sugar as it was mentioned. Which would be where I would reference the first comment posted of UDP vs TCP

Comment button Reply

CollapseExpand

What's the technical purpose for differentiating the Internet Layer and the Transport Layer? Why can't one "layer" handle IP and ports?

Comment button Reply

CollapseExpand

I am not sure of any accepted answer but one reasoning for this separation would be for applications that only implement up to one layer.

If there is a router that only implements up to the internet layer(because it doesn't need port control up to that point) it would easily be able to implement this functionality up the internet layer only.

This also proves the same for software that would only implement up to the network layer such as old switches

Thread

Thread

I agree with this. I'd also expand on this and say that different devices "unwrap" different layers of a packet. So yeah, it wouldn't necessarily make sense for an edge router to care what port is needed. It just needs to know where to send the packet (IP) and the target machine handles the rest.

Comment button Reply

CollapseExpand

separating out being able to figure out where a packet goes (internet layer) from anything about it's contents and purpose (transport layer) allows the infrastructure of the internet to be much simpler. It also means that only the machines communicating with each other need to be concerned with what's being sent and why, and developers can create new transport protocols tailored to their use (though this is usually not a good idea since people end up creating a nock-off tcp).

as an analogy: if the transport layer is the methodology for deciding when and how to chuck packets at each other, the internet layer is the muscles in your arms. They only need to be specialized enough to move the arms. They don't need to be concerned with the manner of packet chucking, nor should they be in case you want to chuck packets differently.

Comment button Reply

CollapseExpand

Layers of misdirection, and I might have to redo this before I can get to the five-year-old level.

My group is in the coffee shop, and there's enough people to require a few tables, and my table runs out. The people at my table know me, and know Dave = "seat nearest the bathroom". This part is MAC address to to IP address, which is done by Address Resolution Protocol, or ARP, and you can use computers your whole life without caring about this.

But next table over doesn't know me or where I sit, so when you ask them (serving as gateway) to pass some sugar, it is the job of the IP layer to handle the sugar-to-table part and the transport to know who to pass it to here.

Plus, on some tables, people just pass left, or right, but some might throw it right to me over the air. Actually, "how it goes" is more the job of transport layer, although which-one's-Dave is part of that.

Comment button Reply

CollapseExpand

I'd suggest you watch this and the next video on the playlist: youtube.com/watch?v=4IMc3CaMhyY&li...

A 5 year old might not understand that, but it'll give you a better overview of how TCP works. For better context read on TCP's features (flow-control, stream and connection oriented, etc.) first.

Comment button Reply

CollapseExpand

CollapseExpand

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

Comment button Reply

CollapseExpand

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.

Comment button Reply

CollapseExpand

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

Comment button Reply

CollapseExpand

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.

Comment button Reply

CollapseExpand

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

Comment button Reply

CollapseExpand


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK