Hello, everyone, welcome to a new video of our Python.
Last time we talked about multi threading in Python and how to receive data from multiple clients at
the same time.
Now, in a back door scenario, we need to interact with a specific target.
But how do we do that?
Remember that we had our socketed object when we accept the connection in a variable rate, but how
do we identify a socket object?
What if we assign a number to each socket object and create a dictionary or a list?
Let's do that.
We will create a variable and assign it an initial value of zero.
Now, every time we accept a socket object, we will increment this variable by one.
Since we don't want to make things complicated, we can create a list of dictionaries, each dictionary
holds the socket object and its corresponding number.
Let's go to the top and create our list.
Now, let's create another list of dictionaries to hold our IP and port and its corresponding socket
number as well.
Very good, but hold on for a second from before, the only thing we did was to reply to our client
with whatever data we received.
But how do we send commands to a specific client when we are inside a while already?
Well, we can open a raw input to to get some commands from the user, but in another thread and leave
our while loop to receive data in the background.
Let's try that.
Let's create another function just to get input from the user and we need it to be in a while loop as
well to keep receiving commands over and over.
We also need our love to do nothing in case the user didn't provide any input.
Now let's run it on a different thread, but we need to do that right before our Lou.
Now let's ride.
Nice see, now our server is still listening in the background and we can still give it some comments,
so far we know that our sockets from the clients are stored in our socket, underscore object lists.
So let's create a function to print a list of the connected clients that are stored in our list.
Very good.
Now, we will call this function if the user type sessions from the C and D function, let's add that
to it.
But.
Now, let's run it.
Very good, what next?
We can now use our commands function to send actual commands to our clients based on their number we
got from our list.
But before we do that, we need another function to send our command to the client.
Let's try the function and call it we will call it send underscore to underscore client.
This function will receive two arguments, the first argument is the client number that we want to send
our data to.
The second argument is the data itself that we want to send.
Next, we need to to look for the dashi and the command we provide and take the third argument, which
should be the session no, we want to interact with.
Let's go to our esteemed function.
Very good.
Now let's check our sessions.
As same way we have two decisions to interact with the first session, which is this client of the top
right corner, that's my session, number one and low point one, I guess we were seated here.
Let's do the same thing with the client who sessions just to make sure, OK.
Sessions, I too.
Hello.
To receive it here.
Very good.
Now we can send and receive data to multiple clients.
Now let's actually look at the client itself.
As you can see, I'm only standing hello from client before the wild and in the while loop, I wait
to receive data here from the server then I printed if I want to, of course you have to.
And finally, I send the word done.
Well, that was all I think we're done with this lesson, thank you and see you in the next one.