Socket具体还可见360云中文档记载
Socket是一个非常古老的协议了 1970年
Socket.AF_Unix======AF意思是 addressFamily 地址簇
Import os
Os.system(data) #执行命令
cmd=Os.popen(data).read() #执行命令 并返回结果
Import commands
Status,command=Commands.getstatusoutput(data) #执行命令 返回结果状态,和结果内容
Sever端
#Echo server program
import socket
import commands
HOST='192.168.18.99' #Symbolic name meaning all available interfaces
PORT=50007 #Arbitrary non-privileged port
s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.bind((HOST,PORT))
s.listen(1)
while 1:
conn,addr=s.accept()
print 'Connected by',addr
while(1):
data=conn.recv(1024)
if not data:
break
print 'Command received from %s:%s' % addr,data
status,cmd_result=commands.getstatusoutput(data)
conn.sendall(cmd_result)
conn.close()
Client端
#Echo Client program
import socket,time
HOST='192.168.18.99' #Server IP
PORT=50007 #Server Port
s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.bind((HOST,PORT))
s.listen(1)
while 1:
cmd=raw_input("Your command is:").strip()
if cmd=='':
continue
s.sendall(cmd)
data=s.recv(4096)
time.sleep(2)
print data
s.close()
SocketServer自带多线程
if __name__==’__main__’:当自调用的时候,执行下面的代码,当被别的模块调用的时候,冒号下面的代码不被执行