-
Notifications
You must be signed in to change notification settings - Fork 20
/
p3_server.py
50 lines (43 loc) · 1.42 KB
/
p3_server.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
44
45
46
47
48
49
50
import time
import sys
from http.server import BaseHTTPRequestHandler, HTTPServer
import instance
HOST_NAME = ''
PORT_NUMBER = 8086
disp_count = 0
RESP_CODE=200
class MyHandler(BaseHTTPRequestHandler):
def do_HEAD(self):
self.send_response(200)
self.send_header('Content-type', 'text/plain')
self.end_headers()
def do_GET(self):
global disp_count
print("IN Get:",self.path)
if (self.path != "/favicon.ico"):
print("***Handle HTTP:",disp_count,self.path)
disp_count += 1
self.process(RESP_CODE)
else:
print(" +++Skipping favico request")
self.send_response(RESP_CODE)
def process(self,status_code):
self.send_response(status_code)
self.send_header('Content-type', 'text/plain')
self.end_headers()
obj = instance.get_instance()
obj.handler(self)
#response = bytes(content, 'UTF-8')
#self.wfile.write(response)
if __name__ == '__main__':
server_class = HTTPServer
if len(sys.argv) >= 2:
PORT_NUMBER =int(sys.argv[1])
httpd = server_class((HOST_NAME, PORT_NUMBER), MyHandler)
print(time.asctime(), 'Server Starts - %s:%s' % (HOST_NAME, PORT_NUMBER))
try:
httpd.serve_forever()
except KeyboardInterrupt:
pass
httpd.server_close()
print(time.asctime(), 'Server Stops - %s:%s' % (HOST_NAME, PORT_NUMBER))