server端代码:
import socket,commandshost = ''port = 1053s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)s.bind((host,port))s.listen(1)while 1: conn,addr = s.accept() while 1: data = conn.recv(1024) cc,bb = commands.getstatusoutput(data) if len(bb.strip()) != 0: conn.sendall(bb) else: conn.sendall("DONE")
client端:
import socket,oss = socket.socket(socket.AF_INET,socket.SOCK_STREAM)host = "www.xiaoran.com"port = 1053s.connect((host,port))while 1: cc = raw_input("plase input your cmd:").strip() if len(cc) == 0:continue s.sendall(cc) data = s.recv(1024) print datas.close()