Simple Webserver in Python 3


#! /usr/local/bin/python3
from http.server import HTTPServer, SimpleHTTPRequestHandler, BaseHTTPRequestHandler
import sys

def start_server(server_class = HTTPServer, handler_class = SimpleHTTPRequestHandler):
    port = 9099
    server_address = ('',port)
    httpd = server_class(server_address, handler_class)
    try:
        print("Serving at port: " + str(port) + ".")
        httpd.serve_forever()
    except KeyboardInterrupt:
        print("\nStopping server.")
        httpd.server_close()
        sys.exit(0)

start_server()


 
 

Leave a Reply

Your email address will not be published. Required fields are marked *