Skip to content

Commit 94b3050

Browse files
committed
Create BaseHTTPServer1.py
1 parent 61fa5c2 commit 94b3050

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

BaseHTTPServer1.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import time
2+
import BaseHTTPServer
3+
4+
5+
HOST = 'localhost' # set you host
6+
PORT = 31337 # set your port
7+
8+
9+
class Server(BaseHTTPServer.BaseHTTPRequestHandler):
10+
11+
def do_HEAD(s):
12+
s.send_response(200)
13+
s.send_header("Content-type", "text/html")
14+
s.end_headers()
15+
16+
def do_GET(s):
17+
s.send_response(200)
18+
s.send_header("Content-type", "text/html")
19+
s.end_headers()
20+
s.wfile.write("<html><head><title>Titles.</title></head>")
21+
s.wfile.write("<body><p>and stuff.</p>")
22+
s.wfile.write("</body></html>")
23+
24+
if __name__ == '__main__':
25+
server_class = BaseHTTPServer.HTTPServer
26+
httpd = server_class((HOST, PORT), Server)
27+
print time.asctime(), "Server On - %s:%s" % (HOST, PORT)
28+
try:
29+
httpd.serve_forever()
30+
except KeyboardInterrupt:
31+
pass
32+
httpd.server_close()
33+
print time.asctime(), "Server Off - %s:%s" % (HOST, PORT)

0 commit comments

Comments
 (0)