字幕列表 影片播放 列印英文字幕 So in this video. I want to walk [through] [a] very simple connection between two computers here So what I'm going to do is I'm going to connect from one ninety two dot [one] sixty eight dot zero dot one forty seven I'm going to make a TCP connection To one ninety [two] dot one sixty eight dot one ninety two dot ten and so usually the [the] device that is initiating that connection is is called the client and Then the device that's connecting to is called a server But of course once they're connected It doesn't really matter who connected to who they can both send data bi-directionally and so what I'm going to do here is I'm going to I'm going to start this connection from Port five six two zero eight which is just kind of a randomly selected port and I'm going to connect to port Thirteen on the server, and then what's going to happen is the way this server Set up is when you connect to port 13 the server is going to send back Just a little bit of text that has the time of day in it and the server's going to disconnect and so this will basically let us walk [through] setting up the connection getting a little bit of data from the server and then walk [through] the disconnection and so the first thing that's going to happen is the client is going to send a packet to the server to Initiate the [connection] and in that packet it's going to give it [the] initial sequence number that the client is going to use and Normally, it'll just pick a random number for for the sequence number, but in in this example. I'll just start with the sequence number Equal to zero just [to] kind of make things simple and to tell it [that] this is the initial Connection it sets. This this syn Bit these are all the flag bits that are in the TCP header and one of the flag bits is the syn Bit which stands for [synchronize] and so it since this sim bit? to tell it to to synchronize this is a new connection and the sequence number is going to be zero and then the server is going to respond by acknowledging that and so it's going to send a packet in the other direction with the acknowledgment bits set and so it's going to say acknowledge and Then it's going to use this acknowledgement [number] to tell it the next sequence number it expects, so it's going to say the acknowledgement number is one Because the client just said it's sequence number zero so the server is going to acknowledge that and say the neck sequence number it expects is one in the same Packet the server is also going to set its own sin, bit and Send its sequence number Which in this case? I'll just say zero, but again. It's going to pick a random sequence number and then the client is going to acknowledge that with an ak with the [acknowledgment] number of one and It's going to set its sequence number To one, and there's no data in this packet, so even though the sequence number is one the server doesn't doesn't receive any data so it's still expecting the next byte of actual data to show up with sequence number one and so at this point with this these three packets back and forth the connection is established, so So at this point the connection is established And so once the connection is established both sides can go ahead and send Data back and forth and So in this particular case there's some software running on the server that whenever anything connects to port 13 It's going to send back the the time of day send back a string with the time of [day] in it And that's going to be Just some data and in this case. Let's say it's 22 bytes bytes Long So there's 22 bytes of data that contain the time of day and so the sequence number for this is going to be sequence number one But then what's going to happen is the client is going to acknowledge that? with an ack and the acknowledgement number is just going to say what the next sequence number to expect so the sequence number was expecting was one right because the Client initially sent Sequence number 0 as the syn and so that the client is now expecting one to be the next sequence number and so it Acknowledges that saying it's acknowledging and saying that one is the next number it expects And now it's receiving something with sequence number one, but it's receiving 22 bytes And so what it's going to do is it's going to saying that the next thing It expects is 23, so it's going to [acknowledge] and say that the next sequence number. It expects is 23 Because it's already received bytes 1 through 22 so the next thing expects is 23 and [then] at this point the server has sent the [the] time and so the server is going to go ahead and disconnect so this is kind of the the [end] of sending Data and the server is now going to Disconnect [and] what it does is it sends a packet with the fin bit set And in this case the sequence number is going to be 23 Because that's the the next sequence number and so the fin bit is just another one of these bits that are in the TCP header and its purpose is [to] is to say that the connection is is finished or We want to disconnect and so the server wants to disconnect So it sends a packet with the fin bit set and it's sequence number 23 and then the client is going to acknowledge that So it sends an ack with the acknowledgement [number] of 24 does it just received 23. It's now going to send back say okay. I got that the next thing I'm expecting is 24 and so at this point the server has closed the connection so the server can't send any more data to the client and Now the the final thing that happens is the client code closes the connection as well So the client is going to send [another] packet here with its fin Bit set so the server sent a fin now the clients turn to send a fin And then the server will finally acknowledge that and so when the client sends this fin it's going to set the sequence number to [one] because if we go back up here remember the first thing the client sent was this sin with a sequence number of 0 and Then the server acknowledged that saying the next thing it's expecting. It's acknowledging it the next sequence number It's expecting is 1 and then the server doesn't send or excuse me the client doesn't send anything other than other than [acknowledgment] So it's just sending this acknowledgment this acknowledgments not sending any data all the data was in this direction So at this point the next next sequence number that the client is going to use is sequence number 1 So it sends its fin with sequence number 1 and then the server Acknowledges that saying that the next sequence number for the client is two and at that point the connection is completely is completely closed and So I actually set this connection up, and we can take a look in wireshark I captured it in Wireshark And so [I'd] [encourage] you to try this as well as go into wireshark and try to capture some TCP Traffic and see what you see [but] [what] we see here is that the first three packets are the setting up the connections So here it shows [you] what flags are set so you can see the syn And then the response with the syn ack And then the response with the ack and so after these three packets here the connection [is] established [so] [we] have the sin the sin with the ack and then the ack and at that point we're established and then at that point the Server can [send] and so this is from the server [192] [10] can send to this destination the actual data and if you look down [here] in the data You can actually see it has the time and date. Which is which is what this particular server does and then you can see the [acknowledgment] again from the client and then the last four packets are the phinn from the server the ack from the client the [phinn] from the client and then the [ack] from the server to close the connection and Wireshark is nice too. Because it tells you the sequence numbers and the acknowledgement numbers in each direction as well so These should all match up the with the scenario that we that we just walked through and one of the other nice things that wireshark Does is you see it's saying sequence number [0] but if we actually look inside the TCP header the sequence number It says sequence number 0 then it says relative sequence number and if you actually look at the data you can see it's actually this 5 1 0 5 b 6 2 1 so it's picking this this kind of random sequence number but wireshark is nice enough to To just sort of subtract out that starting sequence number and then show all of these numbers as relative So it's it's a lot easier to follow that way and so you can see the server is starting with You know sequence number 0 even though it's really this this crazy number and then the acknowledgement From receiving the client is starting with that sequence number zero and then the acknowledgement from the client is saying the [next] thing it's expecting is one When really so this is b six to one if we look at the client and we look at the relative act number It's actually saying b six to two so in reality it's it's adding one to that to that crazy number but wireshark is nice enough to show us the sequence numbers and acknowledgement numbers is as Kind of more more friendly numbers or starting at zero So again, I would I would encourage you to To download wireshark and play with it and try and see if you can you can see TCP in operation like this for yourself
A2 初級 TCP連接演練|網絡教程(13的13) (TCP connection walkthrough | Networking tutorial (13 of 13)) 5 0 林宜悉 發佈於 2021 年 01 月 14 日 更多分享 分享 收藏 回報 影片單字