1 00:00:00,600 --> 00:00:07,530 Today, we will continue our python lessons with these hip sockets to keep you socket is very similar 2 00:00:07,530 --> 00:00:08,210 to Euterpe. 3 00:00:09,330 --> 00:00:11,520 Let's build our TCAP socket first. 4 00:00:18,390 --> 00:00:25,410 So far, the only difference is instead of diagram for UDP, we write Çok Underscore Stream, which 5 00:00:25,410 --> 00:00:26,670 indicates TCP. 6 00:00:30,230 --> 00:00:33,530 Then we need to accept the connection in this line. 7 00:00:35,620 --> 00:00:42,610 This part we didn't have to include with the UDP, but we needed with the DCP, when we accept Conexion, 8 00:00:42,610 --> 00:00:48,670 it returns a tuple containing connection object and remote connection information like IP and port. 9 00:00:49,090 --> 00:00:52,420 Same thing we did with the receiver from Functioning UDP. 10 00:00:53,950 --> 00:00:56,890 This is very important and we will need it a lot later. 11 00:00:58,900 --> 00:01:00,530 We have two variables here. 12 00:01:00,850 --> 00:01:08,590 The first one is C, this one will have the object of our connection, which we will use a lot later 13 00:01:09,640 --> 00:01:11,390 to send and receive data. 14 00:01:12,220 --> 00:01:17,740 The second one is ADR, which holds the IP address and port of the client 15 00:01:20,770 --> 00:01:22,040 in DCP Socket. 16 00:01:22,120 --> 00:01:28,390 We receive data with the received function not received from like UDP. 17 00:01:29,650 --> 00:01:34,600 The length of the data received should be zero one connection is dropped. 18 00:01:34,810 --> 00:01:40,300 Keep that in mind when if you want to track your connections with multiple back doors or clients. 19 00:01:48,110 --> 00:01:53,570 Now, let's send some data to our TCP socket using another Python client on Macarius. 20 00:02:22,960 --> 00:02:24,070 So far, so good. 21 00:02:24,670 --> 00:02:27,070 But what if our client closed the connection? 22 00:02:30,920 --> 00:02:36,860 We need to know that so we can act upon it from the server side, as you see, the server doesn't know 23 00:02:36,860 --> 00:02:38,060 anything about what happened. 24 00:02:39,770 --> 00:02:42,940 We can do that by checking the length of the data we receive. 25 00:02:43,520 --> 00:02:48,530 If the length is zero, then we know the connection or the client closed it. 26 00:02:49,790 --> 00:02:50,570 Let's do that. 27 00:03:36,680 --> 00:03:41,810 It didn't work when we sent some data first, because if we look at our while loop. 28 00:03:44,410 --> 00:03:44,860 Here. 29 00:03:46,670 --> 00:03:48,830 It has to accept the data first. 30 00:03:51,360 --> 00:03:52,570 Then receive data. 31 00:03:53,400 --> 00:03:55,750 So let's try again without sending any data. 32 00:03:55,890 --> 00:03:58,620 We will just connect, then close our connection. 33 00:04:11,650 --> 00:04:15,320 As you see, our server detected the decline to close the connection. 34 00:04:17,560 --> 00:04:19,920 This is just the basics of Tsipi connections. 35 00:04:20,200 --> 00:04:27,490 We will get into more details later when specifically when we talk about and build our own receivals 36 00:04:27,490 --> 00:04:31,540 function, we have reached the end of our TCP socket. 37 00:04:31,570 --> 00:04:33,760 Listen, thank you and see you in the next one.