-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebserver.py
More file actions
29 lines (23 loc) · 932 Bytes
/
webserver.py
File metadata and controls
29 lines (23 loc) · 932 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
from http.server import BaseHTTPRequestHandler, HTTPServer
import time
hostname = "localhost"
port=8080
class MyServer(BaseHTTPRequestHandler):
def do_GETd(self):
self.send_response(200)
self.send_header("Content-type", "text/html")
self.end_headers()
self.wfile.write(bytes("<html><head><title>Basic web server</title></head>", "utf-8"))
self.wfile.write(bytes("<p>Request: %s</p>" % self.path, "utf-8"))
self.wfile.write(bytes("<body>", "utf-8"))
self.wfile.write(bytes("<p>This is an example web server.</p>", "utf-8"))
self.wfile.write(bytes("</body></html>", "utf-8"))
if __name__== "__main__":
webserver = HTTPServer((hostname, port), MyServer)
print("Server started http://%s:%s" % (hostname, port))
try:
webserver.serve_forever()
except KeyboardInterrupt:
pass
webserver.server_close()
print("Server stopped.")