-
Notifications
You must be signed in to change notification settings - Fork 0
/
server-http.py
43 lines (32 loc) · 1.01 KB
/
server-http.py
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import http.server
import socketserver
# -- IP and the port of the server
IP = "localhost" # Localhost means "I": your local machine
PORT = 8002
# HTTPRequestHandler class
class testHTTPRequestHandler(http.server.BaseHTTPRequestHandler):
# GET
def do_GET(self):
# Send response status code
self.send_response(200)
# Send headers
self.send_header('Content-type', 'text/html')
self.end_headers()
# Send message back to client
message = "Hello world! " + self.path
# Write content as utf-8 data
self.wfile.write(bytes(message, "utf8"))
print("File served!")
return
# Handler = http.server.SimpleHTTPRequestHandler
Handler = testHTTPRequestHandler
httpd = socketserver.TCPServer((IP, PORT), Handler)
print("serving at port", PORT)
try:
httpd.serve_forever()
except KeyboardInterrupt:
pass
httpd.server_close()
print("")
print("Server stopped!")
# https://github.com/joshmaker/simple-python-webserver/blob/master/server.py