1 00:00:00,000 --> 00:00:08,000 When using TCP, devices must first establish a connection with a peer system 2 00:00:09,000 --> 00:00:10,000 before data transmission can take place 3 00:00:11,000 --> 00:00:16,000 so connection orientated session will be established between host A and host B 4 00:00:17,000 --> 00:00:23,000 One machine will initiate the connection which must then the accepted by the other machine. 5 00:00:24,000 --> 00:00:28,000 Protocols software modules in the operating systems of the host devices 6 00:00:29,000 --> 00:00:33,000 communicate with each other by sending messages across the network 7 00:00:34,000 --> 00:00:36,000 to verify that the transfer is authorized 8 00:00:37,000 --> 00:00:39,000 and that both sides are ready for the transmission of data. 9 00:00:40,000 --> 00:00:48,000 For this to take place a three-way handshake occurs between the host devices using TCP. 10 00:00:49,000 --> 00:00:55,000 So host initiating the session will set the SYN flag or SYN bit 11 00:00:56,000 --> 00:01:00,000 in the TCP header of the initial segment send to host B. 12 00:01:01,000 --> 00:01:05,000 Host A will also choose an initial sequence number 13 00:01:06,000 --> 00:01:08,000 which in this example let's say 100. 14 00:01:09,000 --> 00:01:12,000 So the control flag SYN is set on 15 00:01:13,000 --> 00:01:16,000 and the sequence number is set to an initial value of 100. 16 00:01:17,000 --> 00:01:20,000 This is then used to start the handshake process. 17 00:01:21,000 --> 00:01:27,000 This synchronization segment also specifies the number of the port 18 00:01:28,000 --> 00:01:32,000 to which the sender wants to connect for instance port 80 or HTTP. 19 00:01:33,000 --> 00:01:38,000 The host on the right hand side will be waiting for a connection request 20 00:01:39,000 --> 00:01:41,000 from the remote client, in this case host A. 21 00:01:42,000 --> 00:01:45,000 when the SYN is received and accepted 22 00:01:46,000 --> 00:01:53,000 host b will send back a TCP segment with both the SYN and ACK flags set. 23 00:01:54,000 --> 00:01:57,000 So the control flags SYN and ACK are set on 24 00:01:58,000 --> 00:02:01,000 and use to negotiate the connection 25 00:02:02,000 --> 00:02:04,000 and acknowledge receipt of the initials synchronization segment of the sender. 26 00:02:05,000 --> 00:02:08,000 B also set an initial sequence number 27 00:02:09,000 --> 00:02:12,000 to indicate the next sequence number of the next byte of data 28 00:02:13,000 --> 00:02:15,000 it expects to receive from host A. 29 00:02:16,000 --> 00:02:21,000 host B also sets the acknowledgement flag to, in this case 101 30 00:02:22,000 --> 00:02:30,000 an ACK flag indicates, the next portion of data, the host expects to receive. 31 00:02:31,000 --> 00:02:34,000 So host A initially sent a sequence number of a 100 32 00:02:35,000 --> 00:02:39,000 and host B, in this case were assuming a window size of 1 33 00:02:40,000 --> 00:02:41,000 sends back an acknowledgement of a 101. 34 00:02:42,000 --> 00:02:47,000 The third step in the three-way handshake is where the initiating host 35 00:02:48,000 --> 00:02:56,000 in this case host A has received the SYN from host B and sends back a TCP segment 36 00:02:57,000 --> 00:03:00,000 with the control field set to ACK, in other words acknowledgement. 36 37 00:03:01,000 --> 00:03:06,000 Host A is therefore acknowledging the next segment it expect to receive from host B 38 00:03:07,000 --> 00:03:11,000 in this case 301, initially host B sent a sequence number of 300. 39 00:03:12,000 --> 00:03:16,000 So host A is expecting the next segment 301. 40 00:03:17,000 --> 00:03:21,000 Host A sets it's sequence number to 101. 41 00:03:22,000 --> 00:03:29,000 The initial segment sent was 100 and the next one in this case is 101 42 00:03:30,000 --> 00:03:32,000 because the SYN bit or SYN flag is unset 43 00:03:33,000 --> 00:03:37,000 this confirms that three-way handshake has completed successfully. 44 00:03:38,000 --> 00:03:45,000 Just to reiterate, the control bits or flags initially A 45 00:03:46,000 --> 00:03:51,000 sends a segment with the SYN bit or SYN flag set on. 46 00:03:52,000 --> 00:03:54,000 So the control flag SYN is set to 1. 46 47 00:03:55,000 --> 00:04:00,000 Host B in the second step of the three-way handshake 48 00:04:01,000 --> 00:04:04,000 sets its control flags or bits to SYN ACK. 49 00:04:05,000 --> 00:04:07,000 In other words the SYN bit is set to 1 50 00:04:08,000 --> 00:04:10,000 and the ACK bit is set to 1. 51 00:04:11,000 --> 00:04:13,000 In the last step of the three-way handshake 52 00:04:14,000 --> 00:04:19,000 Host A sets the ACK bit to 1 or the ACK flag is set on. 53 00:04:21,000 --> 00:04:24,000 The SYN bit or SYN flag is set to 0 to indicate 54 00:04:25,000 --> 00:04:27,000 that the three-way handshake has completed successfully. 55 00:04:28,000 --> 00:04:32,000 Now sequence numbers and acknowledgements can cause a lot confusion 56 00:04:33,000 --> 00:04:34,000 So I'm going to explain them in more detail now. 57 00:04:35,000 --> 00:04:39,000 We're assuming in this example, that a window size of 1 is used. 58 00:04:40,000 --> 00:04:42,000 Now if you remember the window size is the maximum amount of data 59 00:04:43,000 --> 00:04:47,000 that the receiver can receive from a sender and process correctly. 59 60 00:04:48,000 --> 00:04:52,000 So we're going to assume that only 1 segment can be transmitted 61 00:04:53,000 --> 00:04:56,000 at any given time before an acknowledgement is received 62 00:04:57,000 --> 00:04:59,000 to acknowledge receipt of that segment. 63 00:05:00,000 --> 00:05:03,000 So let’s assume A starts with an initial sequence number of 5 64 00:05:04,000 --> 00:05:09,000 because of a window size of 1, only 1 segment can be sent from A to B. 65 00:05:10,000 --> 00:05:14,000 B successfully receives the segment from A 66 00:05:15,000 --> 00:05:19,000 and acknowledges the next segment that it wants to receive. 67 00:05:20,000 --> 00:05:23,000 so rather than acknowledging receipt of sequence number of 5 68 00:05:24,000 --> 00:05:26,000 it acknowledges for sequence number 6 69 00:05:27,000 --> 00:05:32,000 which implies that all previous sequence numbers will receive correctly. 70 00:05:33,000 --> 00:05:37,000 So B acknowledges in this case for sequence number 6 71 00:05:38,000 --> 00:05:41,000 but B may start with an initial sequence number of 10. 71 72 00:05:42,000 --> 00:05:47,000 so in the TCP header B tells A that its initial sequence number is 10 73 00:05:48,000 --> 00:05:52,000 and that its successfully received sequence number 5 from A 74 00:05:53,000 --> 00:05:56,000 and is expecting sequence number 6 from A in the next packet. 75 00:05:57,000 --> 00:06:00,000 Let’s assume successfully receives that segment 76 00:06:01,000 --> 00:06:05,000 so A will now send segment 6 to B 77 00:06:06,000 --> 00:06:08,000 in other words the next sequence number. 78 00:06:09,000 --> 00:06:14,000 A also acknowledges receipt of segment 10 from host B. 79 00:06:15,000 --> 00:06:19,000 So A has successfully received the segment with sequence number 10. 80 00:06:20,000 --> 00:06:21,000 Please note once again that the host 81 00:06:22,000 --> 00:06:24,000 can randomly choose the initial sequence numbers 82 00:06:25,000 --> 00:06:27,000 and thus in the initial three-way handshake 83 00:06:28,000 --> 00:06:31,000 that information needs to be communicated between the 2 hosts 84 00:06:32,000 --> 00:06:34,000 so that they know what the initial sequence numbers are. 84 85 00:06:35,000 --> 00:06:42,000 So once again A sends sequence number 6 to B and acknowledges sequence 11. 86 00:06:43,000 --> 00:06:45,000 Let’s assume B successfully receives that segment 87 00:06:46,000 --> 00:06:49,000 and therefore will acknowledge for segment 7. 88 00:06:50,000 --> 00:06:52,000 The next segment it expects to receive 89 00:06:53,000 --> 00:06:58,000 once again 7 in the acknowledgement indicates that previous segment was successfully received. 90 00:06:59,000 --> 00:07:03,000 So host B by setting the sequence number to 7 is telling host A 91 00:07:04,000 --> 00:07:06,000 that sequence number 6 was successfully received. 92 00:07:07,000 --> 00:07:10,000 Host B sends sequence number 11 93 00:07:11,000 --> 00:07:14,000 because that’s the next sequence number that A expects to receive. 94 00:07:15,000 --> 00:07:19,000 The thing to note once again, is that initial sequence numbers 95 00:07:25,000 --> 00:07:29,000 that the host expects to receive and the sequence of number of for instance 11 96 00:07:30,000 --> 00:07:36,000 implies that sequence number 10 and previous sequence number was successfully received. 97 00:07:37,000 --> 00:07:41,000 Now once again flow control prevents an issue 98 00:07:42,000 --> 00:07:44,000 where the sender is sending so much data 99 99 00:07:45,000 --> 00:07:47,000 that the buffers of the receiver are overflowed. 100 00:07:48,000 --> 00:07:53,000 If this is a very powerful machine and this is an older machine 101 101 00:07:54,000 --> 00:08:00,000 that is not as powerful, it’s possible that A can overrun 102 102 00:08:01,000 --> 00:08:04,000 the buffers of B because it’s sending so much data. 103 103 00:08:05,000 --> 00:08:09,000 So B needs a mechanism to tell A to slowdown 104 00:08:10,000 --> 00:08:13,000 so that D can successfully process the traffic that it’s receiving. 105 105 00:08:14,000 --> 00:08:16,000 So as an example let’s assume 106 00:08:17,000 --> 00:08:21,000 that the window size in this example is 3 rather than 1. 107 107 00:08:22,000 --> 00:08:27,000 So A can send 3 segments of data before getting an acknowledgement. 108 108 00:08:28,000 --> 00:08:32,000 The advantage of increasing the window size is that throughput 109 109 00:08:33,000 --> 00:08:37,000 can increase dramatically because a host can send more data 110 110 00:08:38,000 --> 00:08:43,000 with fewer acknowledgements and therefore the round trip timers decrease dramatically. 111 111 00:08:44,000 --> 00:08:48,000 So in this example A sends 3 segments to B. 112 112 00:08:49,000 --> 00:08:51,000 Let’s assume that the received buffer of B is full 113 00:08:52,000 --> 00:08:54,000 and it can't handle that amount of data 114 114 00:08:55,000 --> 00:08:59,000 B will send a not ready indicator to A 115 115 00:09:00,000 --> 00:09:03,000 and it does this by setting the windows size to 0. 116 00:09:04,000 --> 00:09:06,000 This tells the sender to stop sending data 117 117 00:09:07,000 --> 00:09:09,000 and wait for ready indicator from the receiver. 118 118 00:09:10,000 --> 00:09:15,000 Assuming that host B has now been able to process the data 119 119 00:09:16,000 --> 00:09:19,000 in it’s receive buffer and can now receive more data. 120 120 00:09:20,000 --> 00:09:27,000 It can send a ready indicator to A, to tell it to resume sending of datagrams. 121 00:09:28,000 --> 00:09:33,000 so A resumes the transmission by sending for instance 3 segments to B. 122 122 00:09:34,000 --> 00:09:36,000 Because the window size is 3. 123 123 00:09:37,000 --> 00:09:42,000 So please note in the background the TCP host involve in the conversation 124 00:09:43,000 --> 00:09:47,000 can negotiate various parameters and one of them is flow control 125 125 00:09:48,000 --> 00:09:53,000 where a receiver, can tell a sender to slowdown or to stop sending data 126 126 00:09:54,000 --> 00:09:58,000 until the receiver has buffer space available to receive transmitted segments. 127 00:09:59,000 --> 00:10:02,000 This is allows for communication between a very powerful 128 128 00:10:03,000 --> 00:10:07,000 or fast machine and a slower or less powerful machine 129 129 00:10:08,000 --> 00:10:12,000 where they can negotiate the rate of transmission.