blob: b540ac4712fa8a4b71be4d1344285f5eab5ff3c9 (
plain) (
blame)
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
51
52
53
54
55
56
57
58
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
|