Server code:
Client code:
Python:
import socket
host = 'localhost'
port = 8888
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((host, port))
s.listen(1)
print('Listening for connections...')
while True:
conn, addr = s.accept()
print('Connected by', addr)
while True:
data = conn.recv(1024)
if not data: break
output = subprocess.check_output(data.decode(), shell=True)
conn.sendall(output)
conn.close()
Client code:
Python:
import socket
host = 'localhost'
port = 8888
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((host, port))
while True:
cmd = input("Enter command: ")
s.sendall(cmd.encode())
data = s.recv(1024)
print(data.decode())