我希望我的访问者能够同时使用 HTTP 和 HTTPS。我正在使用一个简单的Python网络服务器,用套接字创建。我遵循了本指南:Python简单SSL套接字服务器,但它并没有那么有用,因为如果证书在其中一个客户端中不可信,服务器就会崩溃。以下是来自我的Web服务器的几行代码,它运行服务器:定义开始(自我):#创建一个套接字对象s = 套接字.socket(socket.AF_INET,套接字。SOCK_STREAM)
# bind the socket object to the address and port
s.bind((self.host, self.port))
# start listening for connections
s.listen(100)
print("Listening at", s.getsockname())
while True:
# accept any new connection
conn, addr = s.accept()
# read the data sent by the client (1024 bytes)
data = conn.recv(1024).decode()
pieces = data.split("\n")
reqsplit = pieces[0].split(" ");
# send back the data to client
resp = self.handleRequests(pieces[0], pieces);
conn.sendall(resp)
# close the connection
conn.close()
慕雪6442864
相关分类