Skip to content
Snippets Groups Projects
verySimpleServer.py 981 B
Newer Older
Sorrel Harriet's avatar
Sorrel Harriet committed
#!/usr/bin/env python3
# above 'she-bang' line makes the script executable from command line

""" A Very Simple Web Server
	Run with ./verySimpleServer.py
	Make sure all scripts are executable
	e.g. for single script:
		 chmod +x verySimpleServer.py
Sorrel Harriet's avatar
Sorrel Harriet committed
	or for a whole directory:
		 chmod -r +x htdocs/
"""

import http.server

PORT = 8000										# specifies the port number to accept connections on
server = http.server.HTTPServer					# instantiates an HTTP server object
handler = http.server.SimpleHTTPRequestHandler 	# instantiates a request handler object
server_address = ("", PORT)						# specifies server directory and port number
Sorrel Harriet's avatar
Sorrel Harriet committed

print("Starting server...")					# outputs a message 
httpd = server(server_address, handler)		# creates the server which will listen at the HTTP socket, dispatching requests to the handler
Sorrel Harriet's avatar
Sorrel Harriet committed
print("serving at port", PORT)				# outputs a message
httpd.serve_forever()						# puts program in infinite loop so that the server can `serve_forever'