Skip to content
Snippets Groups Projects
verySimpleServer.py 956 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 cgi scripts are executable
	for single script:
		 chmod +x script.py
	or for a whole directory:
		 chmod -r +x htdocs/
"""

import http.server
import socketserver

PORT = 8000												# specifies the port number to accept connections on

handler = http.server.SimpleHTTPRequestHandler 			# provides request handler
server_address = ("", PORT)								# specify server directory and port number

print("Starting server...")					# outputs a message 
httpd = socketserver.TCPServer(server_address, handler)		# creates the server, passing it the server address and port number, as well as the CGI handler (httpd stands for HTTP Daemon)
print("serving at port", PORT)				# outputs a message
httpd.serve_forever()						# puts program in infinite loop so that the server can `serve_forever'