What Is a Three-Way Handshake in TCP?

[MUSIC PLAYING] We took a look at doing
a three-way handshake. I want to remind
you how that works. And we’ll look at one
with a protocol analyzer if you want to. So this may be enough. So this host wants
to talk to that host. The very first thing it does,
if I typed in Telnet to that IP address, or to that name, what
would be the first thing that happens? So I’m sitting here and I
say, “Telnet space bubba.com.” What’s the first
thing that happens? DNS. DNS. Fantastic. Then, after that we have
an IP address, we then, because we’re using
Telnet, says, “Oh, TCP.” And TCP says, “I need to set
up a three-way handshake.” It creates a source port. And it goes the well-known port
on the far side for Telnet, which is 23. And it sends its
own SYN request. That’s like me saying,
“Robert, do you want to talk?” So that’s the SYN. We acknowledge that, the server
acknowledges it back to us, and says, “Hey, while
I’m at it, because this is a bidirectional
channel we’re setting up, I’m also going to send you my
own synchronization request.” Meaning, OK, I acknowledge
you want to talk to me, I’m game with that. And, by the way, do you
want to talk with me? So, SYN request here. SYN request and
acknowledgement sent back to the client, that
guy who started it. So we have to do,
finally, is recognize that we acknowledge the SYN
request, and we’re good to go. It’s a three-way handshake. The numbers are funky, though. Can I point out
the funky numbers? Now, do you need to know
this for certification? Absolutely. In the real world, if you’re
troubleshooting at this level, you’re way beyond CCNA. Fair enough. That’s absolutely how it works. So, the guys in TAC who are
digging deep into something might have to find out what’s
happening with an application. But, if I send a
sequence number of 100, I will receive an
acknowledgement back of 101. And these usually
refer to bytes. So, if I send 1 byte of data
with sequence number 100, basically, this client will
receive it and say, “OK, I’m ready to receive 101.” It’s like pay it forward. So, if I say “SYN 100,”
he’ll send ACK 101, and my next sequence
number will be 101. So that’s just from
that part of the story. From his sequence number,
he sent sequence number 300, so the acknowledgment that’ll
come back will be 301. It’s interesting. It’s not natural
for a human being to say, “OK, I
totally get that.” But the concept is, Robert
sends me up to 1,000 bytes. He sends sequence
number 0, for example. He sends me 1,000
bytes, I’m going to send him an acknowledgement
saying “1,001.” Which is his cue is, “OK, great. I can pick up right
at 1,001 and send him my next chunk of data.” So it always increments by one? No. In real data? In real data, it never
increments by one? How does it decide how
much to increment by? By the byte count. So, in the slides,
they use a window size of like 1, just an example. And, when we bring up a
live protocol analyzer, I’ll show you. But, if I’m sending
10 million bytes, I’m going to send maybe
a sequence number of 1. I’ll send you 1,000 bytes. You’ll send me
acknowledgement 1,001. And I’ll pick up at
1,001 in that big– But when you get the
acknowledgement back, it’s always one more than– Yes. OK. That’s what I was– The acknowledgment is
going to be whatever your sequence was plus 1. Thank you for helping me get
that, to clarify your question. It’ll always be
the next number up. Flow control. Here’s an idea. Just an idea. Let’s say that you have
a session established with TCP with the server. And you’re having a great time. Data’s going back and
forth and back and forth. And the sender, which
is usually the server, sends three chunks of data. And then, you’re not
ready to process them. Maybe your computer is busy,
you can’t handle it, whatever. Instead of sending an
acknowledgement saying, “Oh, yeah, send
the next piece,” I can send an acknowledgement
that says “Oh, wait. Even though I got
1,000 bytes of data, I need you to start
at 500 again.” And so it can send
an acknowledgment that says 501 instead of 1,001. And that will train this
guy to say, “Oh, OK. I’m going to go ahead and
resend starting at 501, and I may not send
as many next time, because something happened bad. And so I can shrink what’s
called the window size. So, instead of sending
three chunks of data and then waiting for
acknowledgement– didn’t work out too well. OK, let me send two. And, if that doesn’t work,
maybe I’ll send one.” So it’s self-throttling
if the network isn’t working quite right or a
PC isn’t working quite right. Would we get any
of this with UDP? There is no mechanism
in UDP to even have a clue about the sequencing. It’s all based on TCP. [MUSIC PLAYING]

33 thoughts on “What Is a Three-Way Handshake in TCP?

  1. I like the way he teachs.. evrytime smile on his face .. N it's showing that , sir is actually wants to make the concepts clear to their students .. Well job.. N well explain .. ☺

  2. If Host A sends 1000 bytes starting with seq=0, shouldn't Host B send him ack=1000 and not 1001? 1000 Bytes go from numbers 0-999, so Host B awaits data starting with seq=1000…

  3. im extremely confused at how seq and ack numbers still work.

    so to put it mathematically,
    ack number = seq number + number of bytes sent + 1

    so from 2:33 to 2:43,
    seq number = 0
    number of bytes sent = 1000
    so ack number = 0 + 1000 + 1 = 1001 (which is true as mentioned in the video)

    However, earlier in the video, for the three way handshake, (lets talk about the syn phase specifically)
    seq number = 100
    number of bytes sent = 1
    so shouldn't ack number be 100 + 1 + 1 = 102?

  4. As for the https://youtu.be/LyDqA-dAPW4?t=200 when the instructor says that acknowledgement always "whatever your sequence was, plus 1" is not actually the truth.

    Just made a dump in wireshark to double check. When the server_A sends, for example to server_B, 100 bytes having seq number = 10 (consider handshake is completed) server_A will get the acknowlegement 110 from the server_B (not 111) and the next packet server_A sends will have the seq number 110 so no increment by one whatsoever. The seq number equals the ack got from receiver. seq number accumulates the data already sent by the side it belongs to.

Leave a Reply

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

Copyright © 2019 Explore Mellieha. All rights reserved.