Skip to content
Snippets Groups Projects
Commit 2bcdef31 authored by Francesco Crisafulli's avatar Francesco Crisafulli
Browse files

Add new file

parent a31824b7
No related branches found
No related tags found
No related merge requests found
# Python 3 server example
from http.server import BaseHTTPRequestHandler, HTTPServer
import time
hostName = "localhost"
serverPort = 8080
def generate_content(path):
return f"""
<html>
<head></head>
<body>
<p>'{path}' was requested</p>
</body>
</html>
"""
class MyServer(BaseHTTPRequestHandler):
def do_GET(self):
self.send_response(200)
self.send_header("Content-type", "text/html")
self.end_headers()
self.wfile.write(bytes(generate_content(self.path),"utf-8"))
if __name__ == "__main__":
webServer = HTTPServer((hostName, serverPort), MyServer)
print("Server started on http://%s:%s" % (hostName, serverPort))
try:
webServer.serve_forever()
except KeyboardInterrupt:
pass
webServer.server_close()
print("Server stopped.")
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment