标签:listen demo 消息 with open http协议 http col div list
socket_demo.py
1 # web本质 示例 2 3 import socket 4 5 sk = socket.socket() 6 sk.bind(("127.0.0.1", 8000)) 7 sk.listen(5) 8 9 while 1: 10 conn, addr = sk.accept() 11 data = conn.recv(1024) # 收消息 12 conn.send(b‘HTTP/1.1 200 OK\r\n\r\n‘) # 按照HTTP协议的格式发消息 13 # 从文件读取\ 14 with open("data.html", "rb") as f: 15 msg = f.read() 16 conn.send(msg) # 发消息 17 conn.close()
标签:listen demo 消息 with open http协议 http col div list
原文地址:https://www.cnblogs.com/polite/p/10162228.html