import socket
import threading
server = socket.socket()
# 系結到0.0.0.0:8000埠上,因為0.0.0.0可以讓外部ip地址訪問本服務器.注意系結的是服務器主機的地址
server.bind(('0.0.0.0', 8000))
server.listen()
def handle_sock(sock, addr):
while True:
# sock.send("welcome to server!".encode("utf8"))
tmp_data = sock.recv(1024)
print(tmp_data.decode("utf8"))
# input_data = input()
response_template = '''HTTP/1.1 200 OK
<html>
<head>
<title>Build A Web Server</title>
</head>
<body>
Hello World, this is a very simple HTML document.
</body>
</html>'''
# print(response_template)
sock.send(response_template.encode("utf8"))
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/284893.html
上一篇:protobuf生成問題
下一篇:求助 py怎么實作喚醒功能