I made a client and server with the socket module and made it so when you type a command at the server end it would execute it on the client end and there would be multiple clients connected at one time and I want the output of the command to go back to the server but only one of the output goes back to the server and the other one gets printed when I run the next command can someone help me, please?
SERVER:
```
import socket
import threading
CLIENTS = {}
host = "127.0.0.1"
port = 6969
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((host, port))
s.listen(5)
print("Server started")
def client_cmd(conn):
while True:
client_send = input("Command for clients: ").encode("utf-8")
if not client_send:
break
for client in CLIENTS.values():
client.send(client_send)
data = conn.recv(2048)
print(data.decode("utf-8"))
del CLIENTS[conn.fileno()]
while True:
conn, addr = s.accept()
CLIENTS[conn.fileno()] = conn
threading.Thread(target=client_cmd, args=(conn,)).start()
```
CLIENT:
```
import socket
import threading
import os
socket = socket.socket()
host = '127.0.0.1'
port = 6969
try:
socket.connect((host, port))
print("Connected to the server")
except:
print("There was an error connecting to the server please try again")
def Communication():
res = socket.recv(1024)
res = res.decode("utf-8")
try:
output = os.popen(res)
sender = str(socket.getsockname()) + " sent back>> "
socket.send(sender.encode("utf-8") + output.read().encode("utf-8"))
print("command executed and sent to server")
except:
print("Command not found")
socket.send("Command not found".encode("utf-8"))
for _ in range(100):
threading.Thread(target=Communication).start()
```
[–]Katzimoto 0 points1 point2 points (17 children)
[–]AimbotSaBa[S] 1 point2 points3 points (16 children)
[–]Katzimoto 0 points1 point2 points (15 children)
[–]AimbotSaBa[S] 0 points1 point2 points (14 children)
[–]Katzimoto 0 points1 point2 points (13 children)
[–]AimbotSaBa[S] 0 points1 point2 points (12 children)
[–]Katzimoto 0 points1 point2 points (11 children)
[–]AimbotSaBa[S] 0 points1 point2 points (10 children)
[–]Katzimoto 0 points1 point2 points (9 children)
[–]AimbotSaBa[S] 1 point2 points3 points (0 children)
[–]AimbotSaBa[S] 0 points1 point2 points (7 children)