-
Notifications
You must be signed in to change notification settings - Fork 0
/
httpServer.py
30 lines (26 loc) · 1.16 KB
/
httpServer.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
from http.server import BaseHTTPRequestHandler, HTTPServer
import time
hostName = "localhost"
serverPort = 8080
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("<html><head><title>https://pythonbasics.org</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"))
self.wfile.write(bytes("group19 sending from server", "utf-8"))
# self.wfile.write("This is a string") # cann't send string directly
self.wfile.write(bytes("This is a string ", "utf-8"))
if __name__ == "__main__":
webServer = HTTPServer((hostName, serverPort), MyServer)
print("Server started http://%s:%s" % (hostName, serverPort))
try:
webServer.serve_forever()
except KeyboardInterrupt:
pass
webServer.server_close()
print("Server stopped.")