diff options
| author | UltraQbik <no1skill@yandex.ru> | 2024-08-23 02:49:53 +0300 |
|---|---|---|
| committer | UltraQbik <no1skill@yandex.ru> | 2024-08-23 02:49:53 +0300 |
| commit | c95930a8d1e9724a0b720c6fe4e648d0ee267800 (patch) | |
| tree | f0320c5ffa0199e00868c73d22b50cd252d824c1 | |
| parent | 1743ab0a4fdb380cca245875a3f9f5b17d049019 (diff) | |
| download | httpy-c95930a8d1e9724a0b720c6fe4e648d0ee267800.tar.gz httpy-c95930a8d1e9724a0b720c6fe4e648d0ee267800.zip | |
Add start method
| -rw-r--r-- | main.py | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/main.py b/main.py index c202dea..0ab634f 100644 --- a/main.py +++ b/main.py @@ -59,8 +59,9 @@ class HTTPServer: self.packet_size: int = packet_size self.port: int = port - # client thread list + # client thread list and server thread self.client_threads: list[threading.Thread] = [] + self.server_thread: threading.Thread | None = None # add signaling self.stop_event = threading.Event() @@ -75,10 +76,31 @@ class HTTPServer: self.stop_event.set() for thread in self.client_threads: thread.join() + self.server_thread.join() # close server socket self.sock.close() + def start(self): + """ + Method to start the web server + """ + + # bind and start listening to port + self.sock.bind(('', self.port)) + self.sock.setblocking(False) + self.sock.listen() + + # listen and respond handler + while not self.stop_event.is_set(): + # accept new client + client = ssl_sock_accept(self.sock)[0] + + # create thread for new client and append it to the list + th = threading.Thread(target=lambda x: x, args=[client]) # TODO: this line + self.client_threads.append(th) + th.start() + class HTTPServer: """ |