标签:shell linux服务 recv end tin pen local NPU port
#linux服务器 import socket import subprocess import threading server = socket.socket() server.bind((‘‘, 8888)) server.listen(5) print(‘等待电话.....‘) conn, addr = server.accept() print(‘电话来了......‘) while True: data = conn.recv(10240) cmd = subprocess.Popen(data.decode(‘utf-8‘), shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) stdout = cmd.stdout.read() stderr = cmd.stdout.read() conn.send(stdout + stderr) #客户端 import socket import threading client = socket.socket() client.connect((‘192.168.254.24‘, 8888)) while True: info = input(‘===>:‘) if not info:continue client.send(info.encode(‘utf-8‘)) data = client.recv(10240) print(data.decode(‘utf-8‘))
#全双工电话 #服务器端 import socket import subprocess import threading server = socket.socket() server.bind((‘‘, 8888)) server.listen(5) print(‘等待电话.....‘) conn, addr = server.accept() print(‘电话来了......‘) def recv(): while True: data = conn.recv(10240) print(data.decode(‘utf-8‘)) def send(): while True: data = input(‘===>:‘) conn.send(data.encode(‘utf-8‘)) t1 = threading.Thread(target=recv) t2 = threading.Thread(target=send) t1.start() t2.start() #客户端 import socket import threading client = socket.socket() client.connect((‘localhost‘, 8888)) def send(): while True: info = input(‘===>:‘) client.send(info.encode(‘utf-8‘)) def recv(): while True: data = client.recv(1024) print(data.decode(‘utf-8‘)) t1 = threading.Thread(target=send) t2 = threading.Thread(target=recv) t1.start() t2.start()
标签:shell linux服务 recv end tin pen local NPU port
原文地址:https://www.cnblogs.com/fengzi7314/p/10023683.html