summaryrefslogtreecommitdiff
path: root/project1/proj1_s4498062/webhttp/server.py
diff options
context:
space:
mode:
authorCamil Staps2016-03-02 21:37:50 +0100
committerCamil Staps2016-03-02 21:39:52 +0100
commit436f26b4eb1b38089396374876908fdb06d3c015 (patch)
treed599191368ff027e98a704051dfa04a20d6645d1 /project1/proj1_s4498062/webhttp/server.py
parentAssignment 2 (diff)
Added framework project 1
Diffstat (limited to 'project1/proj1_s4498062/webhttp/server.py')
-rw-r--r--project1/proj1_s4498062/webhttp/server.py59
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