Created
May 6, 2020 00:57
-
-
Save crabmusket/c57433d153a197e0670303025805f603 to your computer and use it in GitHub Desktop.
Python simple HTTP server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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