简单的web服务器
import socket sock=socket.socket() sock.bind(("127.0.0.1",8080)) sock.listen(5) while True: conn,addr=sock.accept() print(addr) data=conn.recv(1024) print(data) conn.send(b"HTTP/1.1 300 OK hello,world") conn.close()
- 响应头和响应体一定要用两个换行分开
简单的web服务器
import socket sock=socket.socket() sock.bind(("127.0.0.1",8080)) sock.listen(5) while True: conn,addr=sock.accept() print(addr) data=conn.recv(1024) print(data) conn.send(b"HTTP/1.1 300 OK hello,world") conn.close()