一、服务器端的实现:
__author__ = socket threading tcplink(sock, addr): (% addr) sock.send() : data = sock.recv() .sleep() data data.decode() == : sock.send((% data.decode()).encode()) sock.close() (% addr) server = socket.socket(socket.AF_INET, socket.SOCK_STREAM) HOST = PORT = server.bind((HOST, PORT)) server.listen() () : sock, addr = server.accept() t = threading.Thread(=tcplink, =(sock, addr)) t.start()
二、客户端的实现:
__author__ = socket sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) HOST = PORT = sock.connect((HOST, PORT)) (sock.recv().decode()) data [, , , , ]: sock.send(data) (sock.recv().decode()) sock.send() sock.close()
本文出自 “时空旅行者” 博客,请务必保留此出处http://siweilai.blog.51cto.com/9233507/1775057
原文地址:http://siweilai.blog.51cto.com/9233507/1775057