socket
server client
服务器端 监听
socket IP+端口 网络通信
本地 网络
stream tcp dgram udp
ftp服务器 传文件 传命令
socket.server 多线程-执行
import socketfrom subprocess import Popen, PIPEHOST = '' # Symbolic name meaning all available interfacesPORT = 50007 # Arbitrary non-privileged ports = socket.socket(socket.AF_INET, socket.SOCK_STREAM)s.bind((HOST, PORT))s.listen(1)conn, addr = s.accept()print 'Connected by', addrwhile 1: cmd = conn.recv(1024) p = Popen(cmd, stdout=PIPE, stderr=PIPE, shell=True) result_stdout = p.stdout.read() result_stderr = p.stderr.read() if result_stdout: conn.send(result_stdout) elif result_stderr: conn.send(result_stderr) if not cmd: breakconn.close()