Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
A simple web server.
import socket
HOST, PORT = '', 8000
listen_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
listen_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
listen_socket.bind((HOST, PORT))
print 'Serving HTTP on port %s ...' % PORT
while True:
client_connection, client_address = listen_socket.accept()
request = client_connection.recv(1024)
print request
http_response = """\
HTTP/1.1 200 OK
Hello, I'm a simple Web Server!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment