I’ve set up a little script that should feed a client with html.
import socket
sock = socket.socket()
sock.bind(('', 8080))
sock.listen(5)
client, adress = sock.accept()
print "Incoming:", adress
print client.recv(1024)
print
client.send("Content-Type: text/html\n\n")
client.send('<html><body></body></html>')
print "Answering ..."
print "Finished."
import os
os.system("pause")
But it is shown as plain text in the browser. Can you please tell what I need to do ? I just can’t find something in google that helps me..
Thanks.
The response header should include a response code indicating success.
Before the Content-Type line, add:
Also, to make the test more visible, put some content in the page:
After the response is sent, close the connection with:
and
As the other posters have noted, terminate each line with
\r\ninstead of\n.Will those additions, I was able to run successful test. In the browser, I entered
localhost:8080.Here’s all the code: