TCP and UDP: Comparing Transport Protocols

Published by Darron Toy on

Music The two major protocols
are TCP and UDP. Here's a side by side
comparison of them. So here's where we started
off and we launched off for the demo and the discussion. So with TCP, it's reliable. Why is that? Because it keeps
track of the sessions. It cares. It's the protocol that cares. It's the guy who
says, 1 of 2, 2 of 2, and I want to make sure
I get these across. And that's when we think
about transport layer. If you're thinking about
TCP, that's what it's doing. It wants acknowledgements. It wants certified mail. It wants receipts to make
sure all the data got there. Now, to do that,
TCP uses something called a three-way handshake. Oh, three-way handshake–
what does that mean? Let's talk about rutabagas. Now, I don't recall what
a rutabaga looks like, but I think it's a vegetable. So if we walked into
a grocery store, and we said to some stranger–
not somebody who worked there. We walked up and said, do you
know where the rutabagas are? He might just pretend
he didn't hear us. Like, OK, OK. But if I walked up to that
same guy and I said, hi, do you know what time it is? And he told me the time
and had a little dialogue. And then I asked him, do you
know where the rutabagas are? Like it or not, he knows
I'm talking to him. So TCP uses– before it actually
communicates and sends data, it does a thing called
a three-way handshake, and it goes like this. Can we demo this, Robert? Sure. OK. So you stay right there. OK. I'm going to say, hi, Robert. I'd like to talk to you. Is that OK? That's fine. Great. So that's a request to
talk– the acknowledgement. And then, if you had just asked
me, will you talk with me? Will you talk with me? I will. And it's a three-way handshake
because the request goes out to Robert. He acknowledges my request
and sends his own request, and then, I acknowledge him. That sounds like four ways. It's four ways, but they
do it in three packets. It's not my fault. But it is
four separate things going on, but it's in three packets. So whether we love
it or don't love it, they call it the
three-way handshake, and TCP does it
every single time. Before we start getting serious
about Telnet or ATP or anything else– it's called a
three way handshake. We, also, do acknowledgments. UDP, on the other hand–
User Datagram Protocol– is the protocol that
couldn't care less. For example, if we took a brick
and threw it over the wall and hope it lands, that would
be a perfect example of UDP at layer-4. It doesn't check. It doesn't want receipts. It just says, I
hope it gets there. It's very similar to IP in
that it is connectionless. It could care less about
any type of acknowledgements or anything else. So why would anybody
ever want to use UDP, which isn't reliable–
best effort– as opposed to TCP? Why would we choose
one over the other? Or why would the
programmers who made it choose one over the other? Well, is it simpler? UDP is simpler. There's virtually
nothing to track. I have my source port, my
destination port, and, woohoo, it's gone. With TCP, I've got
to track everything. This is segment 1
of 10, or whatever, and get acknowledgements. So it is simpler. And here's the real reason. If we're doing– I
don't know if it's ever going to catch on, but voice
over IP, where people are using the data networks as
an integrated network to cover voice and data
and everything else. Voice traffic absolutely
has to get there in a very good period of time. And because of that, the
actual conversations on voice, we use UDP for. We don't want an acknowledgment. If I'm talking with
you on the phone and a little teeny
segment gets lost, it may sound like
that or something. But I don't want
an acknowledgment– oh, I missed this. It's too late. So UDP is streamlined–
very little overhead, quick. Video applications, voiceover
IP, they're using UDP for that. So here's the UDP header. This is the PDU– the segment
information that it adds. And you mentioned,
Susan, it's simpler, and this is how simple it is. It's going to add
the source port. What are we going to
use for the source port? I forget. Whatever. You got it. Something higher than 1,024. And what's the destination
port going to be? It would depend on what
program we're going to run. So if we are running
DNS, the destination port for a DNS request would be
the well-known port of 53. If we're using Trivial
File Transfer Protocol, the destination
port would be 69. And there's a little– if
we go back here real quick and print, play. There's also a checksum,
here, at layer-4. So we can, at least,
verify, mathematically, that I have a segment. I do a little mathematical
formula, tag it at the end. The receiver can do a
little mathematical formula compared to what was sent. If it matches, it was
exactly– hasn't been modified, hasn't been mangled in traffic. Quick example of
a checksum, which applies to layer-2, as well. Let's say the Declaration
of Independence is going to be signed. We have all signed, and we
want to ship it to England. I should use a more
generic example. We have a document that we are
going to send across the ocean, and then, we want to
verify that no words were changed in transit. We could have a formula where
we say, let's take all the Es. We'll count the number of
Es, and on the backside, write the number of Es, but
not tell anybody what it means. So, then, the other
side, when they get it, they can count the number of Es. If it matches, and it
says, well, there's 25 Es. I counted 25 Es, it's
a very good chance that the data hasn't
been modified. That's like what a
checksum does for a living. Except, we use
the entire packet, and we do a really quick
mathematical formula. So if anything got
dropped– we lose a bit– it can check
and verify that with the checksum not matching.

Leave a Reply

Your email address will not be published. Required fields are marked *