http server

在浏览器输入主机ip

import threading

http_server = socket.socket()
http_server.bind(("0.0.0.0", 80))
http_server.listen()


def handler(request, addr):
    print(f"{addr}接收http请求:")
    print(request.recv(1024))
    request.send("nihao".encode("utf-8"))
    request.close()


while True:
    request, addr = http_server.accept()
    threading.Thread(target=handler, args=(request, addr)).start()

你可能感兴趣的:(网络编程)