I am trying to learn server/client sockets in python. I can establish the server and client and make the connection. I would like the server to ask the client to input a command. I would like the command to be TIME and I would like the response to display the current time. How do I do that? Here is my server code: Code: #shell_server.py for python3 import socket import subprocess s= socket.socket(socket.AF_INET,socket.SOCK_STREAM) #s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) s.bind(("0.0.0.0",444)) s.listen(1) while True: connexion, client_address = s.accept() print ("connexion from :" +str(client_address)) while True: connexion.send(bytes("Entrer cmd : ", "utf-8")) cmd = connexion.recv(1024).decode() # p = subprocess.Popen(cmd.split(" "),shell=True p = subprocess.Popen(cmd,shell=True ,stdout=subprocess.PIPE,stderr = subprocess.PIPE) out , err = p.communicate() connexion.send(out) And here is my client code: Code: #shell_client.py for python3 import socket s= socket.socket(socket.AF_INET,socket.SOCK_STREAM) s.connect(("127.0.0.1",444)) while True: data = s.recv(4096) print(data.decode()) cmd = input() s.send(cmd.encode('utf-8')) So how do I input TIME and receive the current time?
i think you have to use python datetime module in server file, and in server file you have to check the client sent text if its "Time" then simply send datetime.now()