Tsipi Sockets, hi, everyone, and welcome back to the course they were going to create this socket
and this client and this will be actually the first time we're going to enable us here in the client
to communicate on our own.
So let me pull up a terminal here and let me increase the size of the window so we can actually assess
our DCP client files.
And after that, let's open the pie chart.
So in order to create our socket and actually enable the communication between the client and server,
we're going to use the socket, the socket function in order to specify a type and use the default TCAP
protocol for communication between the server and client.
So let's hit here the resources folder and I'm going to actually assess the folder six here or the Section
six that we create early on, but will create actually two new files.
OK, uh, pretty close here.
And in Section six, I will create a new item file.
So let's create a new item file and the name of the file is going to be Tsipi Server.
OK, and here we're going to write a script and we are actually going to create this server.
So the very first thing we'll need to do is obviously to import the Python library user, been he and
the Python three, and they may actually get closer here.
OK.
And after that, let's import the socket library and the we have to start a library, import it.
Now it's time to create the GCP type socket object.
So let's write it with socket dot socket.
And here in the brackets let's right socket dot av underscore iiNet.
As you can see this variable is predefined and then the socket, the soc stream.
OK, that's it.
And let's right here this will be as socket underscore GCP.
OK, so here we're creating the circuit variable and everywhere we're with the clear socket underscored
to speed, we're actually referring to the circuit variable we just created for the socket object.
So let's do socket underscore disipio that bind and then this right.
Host and port.
OK, and just sort of the import that we need to pass.
And actually let's just above here define the holes, the port in the buffer space.
So let's write cost equals and let's add the IP address of the host.
Let's create to go to one twenty seven zero zero that one.
This is the IP address and then we need to add the name of the port.
So let's fast forward, which would be quote, some random number, lot like seven hundred fifty six
let's say.
OK, and finally let's try it Bofur size, which will be equal to one thousand and twenty four.
OK, and now as you can see here, we're using the host in the port in order to buy into the socket.
Now the next thing you need to do is to create the little function.
So if a right socket is not listen five, this means that we're going to wait for five consecutive seconds
and listening for our server.
So this statement is referred to as a waiting statement.
Then Lizardo Connection, Colma address or ADR will be equal to socket underscore E.S.P.
Thought I'd say and that's it.
And then let's write with connection.
So here we use a connection variable we would like to print in this right of the square brackets with
the star and then let's write established connection.
OK, so this is how we say that we have a connection that is established.
So this means that we successfully connected with the client and after that, let's write while true
data equals.
Connection that Barack and here were going to write the for, so in the receiving.
We want to convert receiving bitts into a string and this is why we use sexual dysfunction here.
And finally, let's verify that we received the data.
So let's try it.
If not.
Data break and then else print.
And here I will write square brackets, data received.
OK, and then this red dot format and then inside out right data dot the code and the court mechanism
will be UTF slash eight.
And we're right here and and a little connection that send data.
OK, so this is how we're going to be ensuring that we're sending the actual data.
OK.
And if you go higher up, let's add two more parenthesis here because we need them.
OK, so that's it.
Guys, this was how you can create a server.
And now let's go to Section six again and let's look at Python file.
And here we're going to create the client.
So let's write this underscore client.
And here, let's write user slash bin.
Slush envy and then right on through and here, our import against socket, and now it's time to add
the server specifications and they have to match exactly the DP server specifications.
So let's right here again, host will be equal to a hundred and twenty seven, not zero zero to one.
Then let's add fourth will be equal to what was.
Let's let's have a look.
Seven, five, six or seven, five, six.
OK.
And finally, the Bofur size will also be the same.
One hundred and twenty four.
And then here are actually the functions are slightly smaller because we need to have some message that
will transmit and the message will be, hello guys, this is your.
First message.
OK.
And after that, let's write a very simple method, so let's try it with socket, that socket and in
the brackets, let's write socket dot if I need.
Cuomo saw kids not so extreme.
US circuit underscore TCAP, that's it, and then here we were, right circuit.
Underscore TCAP, not.
Connect in here, right hosts call one or OK.
And after that, this right socket underscore.
TCAP.
Not sent in here.
We're sending the actual message to our right message and not in code, so we not only want to send
the message, but we want to encode it so nobody can read it until it reaches its destination.
So let's write UTF slushie, OK, in this right.
Bayardo because socket underscore participial.
Not receive, and then he often says, OK, guys who are already here.
So now let's go to a terminal and actually see how those two are communicating.
So I will just assess the fodder that both pilots are.
So as we are in the folder and if I run airways, you can see the Tsipi server and the client, but
actually I will need to run another window here.
So from the terminal, guys, I'm also going to the same folder because we'll have to run both applications
at the same time.
So let me go here to Section six as well.
OK.
And the first thing I would like to do is to run the server.
So it is running and is listening for the client.
So I will do item and then disappear server totally away and OK, there is a slight error here.
Let's see what it is.
So let's right now Peyton and then disappear server.
So TCAP server Lapua.
And here we get a slight error and I think this is right to the ports.
So let me actually create this portal as one, two, three, four, five, six, two, five.
Actually let's try it again.
And you can see that now the server is actually waiting.
So if we hit next, it doesn't show anything because at the moment the server is waiting for connection.
And let's go to the idea here and actually here.
The fourth time again, going to change to one, two, three, four, five.
Let's say this.
And now since we have the server connected now, we can go to the port.
And if we're right here is you can then write Python and then we can do so.
We want to connect with the DP clients or with this client.
And if I run this, you can see that here we got the message, establish connection and they received.
Hello, guys.
This is your first message.
And as you can see on the server, guys, if I go over here on the server, we actually don't have the
message, but we have that the connection is which was so and we have the feel they received and the
data received was actually going to be received is the message that is coming from the client, which
is hello is your first message.
So this is how the server and the client can actually exchange information?
Yes, I hope this picture was useful and brought with me to the next one, where I'm going to show you
how you can create a whole shop within a server and client.
Thanks for watching.