Service-side code
Import Socketimport subprocesshost = "127.0.0.1" PORT = 5001ip_bind = (host,port) server = Socket.socket () server.bind (ip_ BIND) Server.listen (1) print ("Server is waiting for connected ...") conn, add = Server.accept () print ("Client is Already connected,address is [%s] '% (add[1]) while True: client_data = CONN.RECV () Print (Client_data,type ( Client_data)) a = str (client_data, encoding= "Utf-8") print (A,type (a)) temp = subprocess. Popen (a,stdout=subprocess. PIPE) server_data = Temp.stdout.read () print (Server_data,type (server_data)) Conn.sendall (server_data )
Client code
Import sockethost = "127.0.0.1" PORT = 5001ip_bind = (host,port) client = Socket.socket () client.connect (ip_bind) while True : client_data = input ("client:") Client.sendall (bytes (client_data,encoding= "Utf-8")) server_reply = CLIENT.RECV (+) # print (Server_reply,type (server_reply)) print (str (server_reply))
Python Socket Application Execution command