diff options
Diffstat (limited to 'project1/proj1_s4498062/webhttp/server.py')
-rw-r--r-- | project1/proj1_s4498062/webhttp/server.py | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/project1/proj1_s4498062/webhttp/server.py b/project1/proj1_s4498062/webhttp/server.py new file mode 100644 index 0000000..b540ac4 --- /dev/null +++ b/project1/proj1_s4498062/webhttp/server.py @@ -0,0 +1,59 @@ +"""HTTP Server
+
+This module contains a HTTP server
+"""
+
+import threading
+import socket
+
+
+class ConnectionHandler(threading.Thread):
+ """Connection Handler for HTTP Server"""
+
+ def __init__(self, conn_socket, addr, timeout):
+ """Initialize the HTTP Connection Handler
+
+ Args:
+ conn_socket (socket): socket used for connection with client
+ addr (str): ip address of client
+ timeout (int): seconds until timeout
+ """
+ super(HTTPConnectionHandler, self).__init__()
+ self.daemon = True
+ self.conn_socket = conn_socket
+ self.addr = addr
+ self.timeout = timeout
+
+ def handle_connection(self):
+ """Handle a new connection"""
+ pass
+
+ def run(self):
+ """Run the thread of the connection handler"""
+ self.handle_connection()
+
+
+class Server:
+ """HTTP Server"""
+
+ def __init__(self, hostname, server_port, timeout):
+ """Initialize the HTTP server
+
+ Args:
+ hostname (str): hostname of the server
+ server_port (int): port that the server is listening on
+ timeout (int): seconds until timeout
+ """
+ self.hostname = hostname
+ self.server_port = server_port
+ self.timeout = timeout
+ self.done = False
+
+ def run(self):
+ """Run the HTTP Server and start listening"""
+ while not self.done:
+ pass
+
+ def shutdown(self):
+ """Safely shut down the HTTP server"""
+ self.done = True
|