1 00:00:05,270 --> 00:00:12,910 Tsipi Sockets, hi, everyone, and welcome back to the course they were going to create this socket 2 00:00:12,920 --> 00:00:18,920 and this client and this will be actually the first time we're going to enable us here in the client 3 00:00:18,920 --> 00:00:20,270 to communicate on our own. 4 00:00:20,660 --> 00:00:28,400 So let me pull up a terminal here and let me increase the size of the window so we can actually assess 5 00:00:28,400 --> 00:00:31,130 our DCP client files. 6 00:00:31,370 --> 00:00:34,010 And after that, let's open the pie chart. 7 00:00:34,250 --> 00:00:40,280 So in order to create our socket and actually enable the communication between the client and server, 8 00:00:40,520 --> 00:00:47,620 we're going to use the socket, the socket function in order to specify a type and use the default TCAP 9 00:00:47,750 --> 00:00:51,410 protocol for communication between the server and client. 10 00:00:51,440 --> 00:01:00,260 So let's hit here the resources folder and I'm going to actually assess the folder six here or the Section 11 00:01:00,260 --> 00:01:05,540 six that we create early on, but will create actually two new files. 12 00:01:05,690 --> 00:01:08,860 OK, uh, pretty close here. 13 00:01:09,170 --> 00:01:12,850 And in Section six, I will create a new item file. 14 00:01:13,430 --> 00:01:20,900 So let's create a new item file and the name of the file is going to be Tsipi Server. 15 00:01:21,220 --> 00:01:27,280 OK, and here we're going to write a script and we are actually going to create this server. 16 00:01:27,470 --> 00:01:36,680 So the very first thing we'll need to do is obviously to import the Python library user, been he and 17 00:01:36,680 --> 00:01:41,090 the Python three, and they may actually get closer here. 18 00:01:41,330 --> 00:01:41,670 OK. 19 00:01:42,380 --> 00:01:49,160 And after that, let's import the socket library and the we have to start a library, import it. 20 00:01:49,310 --> 00:01:52,570 Now it's time to create the GCP type socket object. 21 00:01:53,030 --> 00:01:57,670 So let's write it with socket dot socket. 22 00:01:58,370 --> 00:02:06,320 And here in the brackets let's right socket dot av underscore iiNet. 23 00:02:06,470 --> 00:02:17,410 As you can see this variable is predefined and then the socket, the soc stream. 24 00:02:17,900 --> 00:02:19,460 OK, that's it. 25 00:02:20,000 --> 00:02:26,460 And let's right here this will be as socket underscore GCP. 26 00:02:27,160 --> 00:02:34,020 OK, so here we're creating the circuit variable and everywhere we're with the clear socket underscored 27 00:02:34,040 --> 00:02:40,180 to speed, we're actually referring to the circuit variable we just created for the socket object. 28 00:02:40,640 --> 00:02:48,590 So let's do socket underscore disipio that bind and then this right. 29 00:02:48,590 --> 00:02:50,790 Host and port. 30 00:02:51,140 --> 00:02:53,600 OK, and just sort of the import that we need to pass. 31 00:02:53,990 --> 00:02:59,210 And actually let's just above here define the holes, the port in the buffer space. 32 00:02:59,570 --> 00:03:05,240 So let's write cost equals and let's add the IP address of the host. 33 00:03:05,540 --> 00:03:09,850 Let's create to go to one twenty seven zero zero that one. 34 00:03:11,060 --> 00:03:15,440 This is the IP address and then we need to add the name of the port. 35 00:03:15,440 --> 00:03:22,520 So let's fast forward, which would be quote, some random number, lot like seven hundred fifty six 36 00:03:23,150 --> 00:03:23,780 let's say. 37 00:03:24,290 --> 00:03:32,930 OK, and finally let's try it Bofur size, which will be equal to one thousand and twenty four. 38 00:03:33,470 --> 00:03:40,370 OK, and now as you can see here, we're using the host in the port in order to buy into the socket. 39 00:03:40,580 --> 00:03:45,330 Now the next thing you need to do is to create the little function. 40 00:03:45,650 --> 00:03:55,880 So if a right socket is not listen five, this means that we're going to wait for five consecutive seconds 41 00:03:56,900 --> 00:03:58,860 and listening for our server. 42 00:03:58,880 --> 00:04:01,820 So this statement is referred to as a waiting statement. 43 00:04:02,330 --> 00:04:14,200 Then Lizardo Connection, Colma address or ADR will be equal to socket underscore E.S.P. 44 00:04:15,260 --> 00:04:17,600 Thought I'd say and that's it. 45 00:04:17,600 --> 00:04:19,980 And then let's write with connection. 46 00:04:20,360 --> 00:04:27,540 So here we use a connection variable we would like to print in this right of the square brackets with 47 00:04:27,540 --> 00:04:31,340 the star and then let's write established connection. 48 00:04:31,700 --> 00:04:36,390 OK, so this is how we say that we have a connection that is established. 49 00:04:37,100 --> 00:04:46,730 So this means that we successfully connected with the client and after that, let's write while true 50 00:04:47,240 --> 00:04:49,190 data equals. 51 00:04:50,580 --> 00:04:59,200 Connection that Barack and here were going to write the for, so in the receiving. 52 00:04:59,520 --> 00:05:06,360 We want to convert receiving bitts into a string and this is why we use sexual dysfunction here. 53 00:05:06,630 --> 00:05:10,000 And finally, let's verify that we received the data. 54 00:05:10,320 --> 00:05:11,060 So let's try it. 55 00:05:11,070 --> 00:05:11,730 If not. 56 00:05:12,910 --> 00:05:16,340 Data break and then else print. 57 00:05:16,480 --> 00:05:22,060 And here I will write square brackets, data received. 58 00:05:22,210 --> 00:05:33,690 OK, and then this red dot format and then inside out right data dot the code and the court mechanism 59 00:05:33,700 --> 00:05:36,570 will be UTF slash eight. 60 00:05:37,890 --> 00:05:44,880 And we're right here and and a little connection that send data. 61 00:05:45,000 --> 00:05:50,070 OK, so this is how we're going to be ensuring that we're sending the actual data. 62 00:05:50,280 --> 00:05:50,890 OK. 63 00:05:50,970 --> 00:05:56,790 And if you go higher up, let's add two more parenthesis here because we need them. 64 00:05:56,940 --> 00:05:58,230 OK, so that's it. 65 00:05:58,270 --> 00:06:01,870 Guys, this was how you can create a server. 66 00:06:02,100 --> 00:06:08,490 And now let's go to Section six again and let's look at Python file. 67 00:06:08,490 --> 00:06:11,120 And here we're going to create the client. 68 00:06:11,370 --> 00:06:14,120 So let's write this underscore client. 69 00:06:14,130 --> 00:06:20,460 And here, let's write user slash bin. 70 00:06:21,630 --> 00:06:32,400 Slush envy and then right on through and here, our import against socket, and now it's time to add 71 00:06:32,400 --> 00:06:39,700 the server specifications and they have to match exactly the DP server specifications. 72 00:06:40,050 --> 00:06:49,390 So let's right here again, host will be equal to a hundred and twenty seven, not zero zero to one. 73 00:06:49,730 --> 00:06:56,100 Then let's add fourth will be equal to what was. 74 00:06:56,300 --> 00:06:57,800 Let's let's have a look. 75 00:06:58,320 --> 00:07:01,650 Seven, five, six or seven, five, six. 76 00:07:01,660 --> 00:07:02,080 OK. 77 00:07:02,520 --> 00:07:07,410 And finally, the Bofur size will also be the same. 78 00:07:07,690 --> 00:07:09,450 One hundred and twenty four. 79 00:07:10,410 --> 00:07:16,500 And then here are actually the functions are slightly smaller because we need to have some message that 80 00:07:16,520 --> 00:07:24,300 will transmit and the message will be, hello guys, this is your. 81 00:07:25,830 --> 00:07:27,450 First message. 82 00:07:27,720 --> 00:07:28,200 OK. 83 00:07:28,950 --> 00:07:37,080 And after that, let's write a very simple method, so let's try it with socket, that socket and in 84 00:07:37,080 --> 00:07:42,570 the brackets, let's write socket dot if I need. 85 00:07:43,790 --> 00:07:50,150 Cuomo saw kids not so extreme. 86 00:07:51,660 --> 00:07:57,720 US circuit underscore TCAP, that's it, and then here we were, right circuit. 87 00:07:59,850 --> 00:08:03,260 Underscore TCAP, not. 88 00:08:04,560 --> 00:08:11,510 Connect in here, right hosts call one or OK. 89 00:08:12,360 --> 00:08:16,290 And after that, this right socket underscore. 90 00:08:17,360 --> 00:08:18,170 TCAP. 91 00:08:20,460 --> 00:08:22,590 Not sent in here. 92 00:08:22,620 --> 00:08:30,930 We're sending the actual message to our right message and not in code, so we not only want to send 93 00:08:30,930 --> 00:08:37,850 the message, but we want to encode it so nobody can read it until it reaches its destination. 94 00:08:38,220 --> 00:08:43,680 So let's write UTF slushie, OK, in this right. 95 00:08:43,680 --> 00:08:50,550 Bayardo because socket underscore participial. 96 00:08:51,670 --> 00:08:58,670 Not receive, and then he often says, OK, guys who are already here. 97 00:08:58,960 --> 00:09:03,860 So now let's go to a terminal and actually see how those two are communicating. 98 00:09:04,450 --> 00:09:07,740 So I will just assess the fodder that both pilots are. 99 00:09:08,200 --> 00:09:15,370 So as we are in the folder and if I run airways, you can see the Tsipi server and the client, but 100 00:09:15,370 --> 00:09:18,710 actually I will need to run another window here. 101 00:09:19,000 --> 00:09:27,490 So from the terminal, guys, I'm also going to the same folder because we'll have to run both applications 102 00:09:27,490 --> 00:09:28,360 at the same time. 103 00:09:28,780 --> 00:09:32,530 So let me go here to Section six as well. 104 00:09:32,770 --> 00:09:33,190 OK. 105 00:09:33,760 --> 00:09:36,820 And the first thing I would like to do is to run the server. 106 00:09:36,820 --> 00:09:39,420 So it is running and is listening for the client. 107 00:09:39,760 --> 00:09:47,840 So I will do item and then disappear server totally away and OK, there is a slight error here. 108 00:09:48,670 --> 00:09:50,020 Let's see what it is. 109 00:09:50,440 --> 00:09:55,690 So let's right now Peyton and then disappear server. 110 00:09:55,810 --> 00:09:59,220 So TCAP server Lapua. 111 00:09:59,380 --> 00:10:03,300 And here we get a slight error and I think this is right to the ports. 112 00:10:03,760 --> 00:10:10,150 So let me actually create this portal as one, two, three, four, five, six, two, five. 113 00:10:10,150 --> 00:10:11,470 Actually let's try it again. 114 00:10:11,860 --> 00:10:15,060 And you can see that now the server is actually waiting. 115 00:10:15,340 --> 00:10:23,320 So if we hit next, it doesn't show anything because at the moment the server is waiting for connection. 116 00:10:23,560 --> 00:10:27,070 And let's go to the idea here and actually here. 117 00:10:27,070 --> 00:10:30,340 The fourth time again, going to change to one, two, three, four, five. 118 00:10:31,420 --> 00:10:32,320 Let's say this. 119 00:10:32,830 --> 00:10:38,860 And now since we have the server connected now, we can go to the port. 120 00:10:39,280 --> 00:10:47,500 And if we're right here is you can then write Python and then we can do so. 121 00:10:47,500 --> 00:10:52,810 We want to connect with the DP clients or with this client. 122 00:10:52,810 --> 00:10:58,860 And if I run this, you can see that here we got the message, establish connection and they received. 123 00:10:59,140 --> 00:10:59,930 Hello, guys. 124 00:10:59,980 --> 00:11:01,270 This is your first message. 125 00:11:01,540 --> 00:11:11,890 And as you can see on the server, guys, if I go over here on the server, we actually don't have the 126 00:11:11,890 --> 00:11:20,880 message, but we have that the connection is which was so and we have the feel they received and the 127 00:11:20,890 --> 00:11:26,020 data received was actually going to be received is the message that is coming from the client, which 128 00:11:26,020 --> 00:11:27,900 is hello is your first message. 129 00:11:28,630 --> 00:11:32,170 So this is how the server and the client can actually exchange information? 130 00:11:32,190 --> 00:11:36,940 Yes, I hope this picture was useful and brought with me to the next one, where I'm going to show you 131 00:11:36,940 --> 00:11:41,100 how you can create a whole shop within a server and client. 132 00:11:41,350 --> 00:11:42,280 Thanks for watching.