标签:read error pre erro base enc sockets end python
# socket 底层模块
# socketserver 基于socket完成的
# tcp协议的server端处理并发的客户端请求
# 网盘 : 文件的上传和下载
server 端
import time
import socketserver
class Myserver(socketserver.BaseRequestHandler):
def handle(self):
conn = self.request
while True:
try:
content = conn.recv(1024).decode(‘utf-8‘)
conn.send(content.upper().encode(‘utf-8‘))
time.sleep(0.5)
except ConnectionResetError:
break
server = socketserver.ThreadingTCPServer((‘127.0.0.1‘,9001),Myserver)
server.serve_forever()
client端
import socket
sk = socket.socket()
sk.connect((‘127.0.0.1‘,9001))
while True:
sk.send(b‘hello‘)
content = sk.recv(1024).decode(‘utf-8‘)
print(content)
标签:read error pre erro base enc sockets end python
原文地址:https://www.cnblogs.com/shaohuagu/p/12261549.html