Today, we will continue our python lessons with these hip sockets to keep you socket is very similar
to Euterpe.
Let's build our TCAP socket first.
So far, the only difference is instead of diagram for UDP, we write Çok Underscore Stream, which
indicates TCP.
Then we need to accept the connection in this line.
This part we didn't have to include with the UDP, but we needed with the DCP, when we accept Conexion,
it returns a tuple containing connection object and remote connection information like IP and port.
Same thing we did with the receiver from Functioning UDP.
This is very important and we will need it a lot later.
We have two variables here.
The first one is C, this one will have the object of our connection, which we will use a lot later
to send and receive data.
The second one is ADR, which holds the IP address and port of the client
in DCP Socket.
We receive data with the received function not received from like UDP.
The length of the data received should be zero one connection is dropped.
Keep that in mind when if you want to track your connections with multiple back doors or clients.
Now, let's send some data to our TCP socket using another Python client on Macarius.
So far, so good.
But what if our client closed the connection?
We need to know that so we can act upon it from the server side, as you see, the server doesn't know
anything about what happened.
We can do that by checking the length of the data we receive.
If the length is zero, then we know the connection or the client closed it.
Let's do that.
It didn't work when we sent some data first, because if we look at our while loop.
Here.
It has to accept the data first.
Then receive data.
So let's try again without sending any data.
We will just connect, then close our connection.
As you see, our server detected the decline to close the connection.
This is just the basics of Tsipi connections.
We will get into more details later when specifically when we talk about and build our own receivals
function, we have reached the end of our TCP socket.
Listen, thank you and see you in the next one.