上代码,server端:
import socket,os s = socket.socket(socket.AF_INET,socket.SOCK_STREAM) host = ‘‘ port = 1051 s.bind((host,port)) s.listen(4) while 1: conn,addr = s.accept() while 1: data = conn.recv(1024) if not data:break os.system(data) conn.sendall(data.upper()) #把字符变为大写 conn.close()
client端:
import socket,os s = socket.socket(socket.AF_INET,socket.SOCK_STREAM) host = "www.xiaoran.com" port = 1051 s.connect((host,port)) while 1: cmd = raw_input("Input Your Commend:").strip() s.sendall(cmd) data = s.recv(1024) print("OK"),repr(data) s.close()
本文出自 “秋风习习” 博客,请务必保留此出处http://aitiankong.blog.51cto.com/8923090/1565328
【学习笔记】Python网络编程(三)利用socket模拟ssh协议
原文地址:http://aitiankong.blog.51cto.com/8923090/1565328