I have a very simple web sever written in Python. It listens on port 13000, how can I make it deliver a simple “Hello World” webpage if http://localhost:13000 is opened in browser?
Right there is my code:
# set up socket and connection
while True:
sock, addr = servSock.accept()
# WHAT GOES HERE?
sock.close()
As you can see, I am not exactly sure how to actually send back the webpage?
I only have to use the socket library.
EDIT: The problem is not that I don’t know how to formulate the HTTP response, I don’t know how to actually make it display in my browser! It just keeps spinning/loading.
Updated according to question change
Possibly, it keeps spinning because in combination of absence of
Content-LengthandConnectionheaders, browser may assume it’sConnection: keep-alive, so it continues to receive data from your server forever. Try to sendConnection: close, and pass actualContent-Lengthto see if that helps.Won’t this do what you expect it to? 🙂
For more detailed description, please see description of HTTP protocol.