Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Python simple HTTP server
# https://blog.notryan.com/server.py
# https://www.reddit.com/r/programming/comments/gdxh3w/http_blog_server_100_lines_of_c_in_a_closet/fpkqvqw/
import socket
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.bind(("0.0.0.0", 8080))
sock.listen(1)
while True:
(csock, addr) = sock.accept()
req = csock.recv(1024)
print(req)
csock.send(b'HTTP/1.0 200 OK\r\n\r\n');
csock.send(b'Hello World!\r\n')
csock.send(b'View the source code here: https://blog.notryan.com/server.py\r\n\r\n')
csock.send(req)
csock.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment