Skip to content

Instantly share code, notes, and snippets.

@kchodorow
Created May 12, 2015 16:35
Show Gist options
  • Save kchodorow/61748e14bac45780a19e to your computer and use it in GitHub Desktop.
Save kchodorow/61748e14bac45780a19e to your computer and use it in GitHub Desktop.
A very basic server
import time
import BaseHTTPServer
HOST_NAME = 'localhost'
PORT_NUMBER = 9000 # Choose a number > 1024.
class MyHandler(BaseHTTPServer.BaseHTTPRequestHandler):
def do_GET(s):
"""Respond to a GET request."""
s.send_response(200)
s.send_header("Content-type", "text/html")
s.end_headers()
s.wfile.write("<html><head><title>Title goes here.</title></head>")
s.wfile.write("<body><p>This is a test.</p>")
# If someone went to "http://localhost:9000/foo/bar/",
# then s.path equals "/foo/bar/".
s.wfile.write("<p>You accessed path: %s</p>" % s.path)
s.wfile.write("</body></html>")
if __name__ == '__main__':
server_class = BaseHTTPServer.HTTPServer
httpd = server_class((HOST_NAME, PORT_NUMBER), MyHandler)
print time.asctime(), "Server Starts - %s:%s" % (HOST_NAME, PORT_NUMBER)
httpd.serve_forever()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment