1 00:00:04,670 --> 00:00:10,550 Sockets, hello, everyone, and welcome back to this video, and today we're going to talk about sockets 2 00:00:10,760 --> 00:00:15,240 and one what actually sockets are when we're talking about network connection. 3 00:00:15,560 --> 00:00:17,600 So basically socket in python. 4 00:00:17,600 --> 00:00:25,610 So socket is a python term that is basically used in there as a standard interface of the transport 5 00:00:25,610 --> 00:00:29,930 layer or the Tsipi or the you or the players. 6 00:00:30,260 --> 00:00:33,480 So this is basically a way to transport data. 7 00:00:33,500 --> 00:00:41,990 So when you run a socket in Python, it basically interacts with a Tsipi and the UDP transport layer 8 00:00:41,990 --> 00:00:42,560 of types. 9 00:00:42,770 --> 00:00:50,090 And also it is looking up for the DNS, which is the hostname or the IP address. 10 00:00:50,220 --> 00:00:57,650 A socket is defined basically by the IP address of the machine, also on the part of which it listens. 11 00:00:57,830 --> 00:01:04,400 And the protocol which uses, for example, if you have a socket, it will be connected to the IP address 12 00:01:04,400 --> 00:01:05,380 of certain machine. 13 00:01:05,600 --> 00:01:09,230 It will listen for certain ports to get access. 14 00:01:09,440 --> 00:01:13,930 And also it will it will use certain protocol, whether TCAP or UDP. 15 00:01:14,210 --> 00:01:24,380 So sockets are basically classified into stream sockets and into we can either have stream sockets or 16 00:01:24,440 --> 00:01:29,460 data grum sockets depending on whether the services dissipate or Euterpe. 17 00:01:29,900 --> 00:01:36,710 So if the service, for example, is Tsipi, then we have a stream socket and if the service is be to 18 00:01:36,710 --> 00:01:41,140 have a diagram socket at the same time, they also classified by family. 19 00:01:41,150 --> 00:01:47,450 For example, if you want to talk about the Unix sockets, which is specific to Unix, then you would 20 00:01:47,450 --> 00:01:49,490 have the sockets that RF Unix. 21 00:01:49,490 --> 00:01:50,900 So GSM sockets. 22 00:01:51,170 --> 00:01:58,010 Then if you want to talk for sockets, depending on the networks that they are based on, then you would 23 00:01:58,010 --> 00:02:00,140 say OK is not a definite file. 24 00:02:00,170 --> 00:02:06,230 And finally, if you want to define sockets, the family of sockets, depending on the type of Internet 25 00:02:06,230 --> 00:02:11,520 connection, then for example, we will have an ID six or eight for socket. 26 00:02:11,540 --> 00:02:15,290 So for example, guys, Destra sockets here they are based on family. 27 00:02:16,520 --> 00:02:18,920 OK, so these are all the female sockets. 28 00:02:18,920 --> 00:02:26,180 In the same time, you can have the sockets based on socket type, for example, here, right type. 29 00:02:26,840 --> 00:02:33,710 So basal socket type there will be three and so Deji rom so so stream. 30 00:02:34,040 --> 00:02:45,620 This is related to the TCAP protocol while the socket teacher is related to the UDP, protocol is important 31 00:02:45,620 --> 00:02:46,410 to understand. 32 00:02:46,550 --> 00:02:53,690 So after we know this, let's go now to the terminal and do some operations with sockets. 33 00:02:54,080 --> 00:02:57,910 So first of all, you need to install a socket package in your computer. 34 00:02:58,100 --> 00:03:03,500 You can simply to pipe the install sockets. 35 00:03:04,340 --> 00:03:11,750 OK, misspelled this with the sockets and you can see that requirement already satisfactorily have it 36 00:03:11,750 --> 00:03:12,910 installed in my computer. 37 00:03:13,190 --> 00:03:17,360 But if you don't have it, you will see this ledman. 38 00:03:17,510 --> 00:03:18,100 Install it. 39 00:03:18,380 --> 00:03:20,000 OK, install sockets. 40 00:03:20,640 --> 00:03:21,470 Yes. 41 00:03:22,130 --> 00:03:24,070 And let me install it back again. 42 00:03:24,710 --> 00:03:29,810 So you see that if you don't have it installed it also. 43 00:03:29,810 --> 00:03:30,590 So like this. 44 00:03:30,990 --> 00:03:34,670 So it collects all the sockets and then starts the installation in. 45 00:03:34,680 --> 00:03:35,720 This mission is complete. 46 00:03:36,410 --> 00:03:40,460 This is one of the fastest installing packages in your computer. 47 00:03:40,700 --> 00:03:42,510 So it will be quite straightforward. 48 00:03:42,650 --> 00:03:51,590 So for example, if I want to assess the sockets from the terminal, you can simply write Python and 49 00:03:51,590 --> 00:03:57,170 then as you can see, you getting to the Python terminal and now you can write a different python commands. 50 00:03:57,170 --> 00:04:03,450 For example, if I write a print statement, for example, if I write print one, then it returns one 51 00:04:03,530 --> 00:04:07,520 or print hello. 52 00:04:07,580 --> 00:04:09,890 So if I print hello, the system will return. 53 00:04:09,980 --> 00:04:10,450 Hello. 54 00:04:11,270 --> 00:04:15,290 And this means that we are assessing the python environment in here. 55 00:04:15,290 --> 00:04:19,300 We can simply import sockets or socket actually. 56 00:04:19,430 --> 00:04:24,260 And for example, I would like to create a socket object for you can do the following. 57 00:04:24,270 --> 00:04:37,100 You can write client socket equals socket dot socket and then the briquettes. 58 00:04:37,100 --> 00:04:51,490 You can write sockets not AV underscored by net comma socket dot soc underscore stream. 59 00:04:51,620 --> 00:04:55,100 OK, and if you see the presentation you can see that when you create socket. 60 00:04:55,430 --> 00:05:02,990 First of all, we define the net in the middle of the socket, which in that case is a if I net and. 61 00:05:03,050 --> 00:05:12,900 Also, we define the title of the circuit, which is the s t r e om, which is a TCAP protocol. 62 00:05:13,580 --> 00:05:19,450 OK, so if a hit OK, you see, we're not getting any errors, which means that our circuit is created. 63 00:05:19,460 --> 00:05:27,440 And for example, if you will not connect the socket to the server, we can usually do that with the 64 00:05:27,440 --> 00:05:28,340 connect command. 65 00:05:28,600 --> 00:05:31,650 We can Deucalion underscore socket. 66 00:05:31,970 --> 00:05:35,360 So this is basically the name of our socket dot connect. 67 00:05:35,940 --> 00:05:43,760 OK, dot, sorry, let's open bracket and let's write the name of the website that we want to connect 68 00:05:43,760 --> 00:05:44,430 to in the web. 69 00:05:45,020 --> 00:05:53,170 So I'll write your dot com comma a t. 70 00:05:54,290 --> 00:06:00,050 So here we're connecting to you took dot com on the circuit edge so we connect to the web server. 71 00:06:00,260 --> 00:06:01,970 So here is an area guys. 72 00:06:02,000 --> 00:06:07,550 I actually put that into the apprentice's. 73 00:06:07,550 --> 00:06:08,870 So let's change that. 74 00:06:08,880 --> 00:06:12,050 And you can see that now our coaches accept it. 75 00:06:12,050 --> 00:06:17,000 And here it says the Afnan through the tuple and now which is a tuple, which is fine. 76 00:06:17,390 --> 00:06:26,810 So here now we created basically a connection to the Web server of YouTube on birthweight. 77 00:06:27,050 --> 00:06:30,680 Also Littlefeather Colman's, for example, the BINDE command. 78 00:06:30,890 --> 00:06:32,560 So let's create an arrow socket. 79 00:06:32,570 --> 00:06:33,800 So I'll right here. 80 00:06:35,270 --> 00:06:45,680 Server socket equals socket dot socket in here. 81 00:06:45,680 --> 00:06:46,250 All right. 82 00:06:47,360 --> 00:07:00,910 Socket dot a.f. i net Colma socket dot soc stream. 83 00:07:00,920 --> 00:07:04,620 So we created the socket which is with the Tsipi protocol. 84 00:07:06,200 --> 00:07:08,260 Now let's run this, OK? 85 00:07:08,570 --> 00:07:20,000 And now we're going to bind the socket and now we can make this and now let's make server socket Douglaston 86 00:07:20,150 --> 00:07:20,630 then. 87 00:07:20,660 --> 00:07:24,180 Which means that our socket will listen for maximum ten connections. 88 00:07:24,920 --> 00:07:27,690 OK, that's it. 89 00:07:27,800 --> 00:07:30,130 So this is how we deal with talk of the case. 90 00:07:30,320 --> 00:07:33,020 I hope this lecture was quite informative for you. 91 00:07:33,290 --> 00:07:37,450 And that said, thank you very much for watching and I will see you in the next video.