diff --git a/shell.nix b/shell.nix index cd5e00d..d251118 100644 --- a/shell.nix +++ b/shell.nix @@ -9,8 +9,9 @@ pkgs.mkShell { pkgs.python312Packages.bleach pkgs.python312Packages.beautifulsoup4 pkgs.python312Packages.pygraphviz + pkgs.python312Packages.requests_toolbelt ]; shellHook = '' - python main.py + python src/main.py ''; } diff --git a/src/lib/server.py b/src/lib/server.py index 587a960..e115af3 100644 --- a/src/lib/server.py +++ b/src/lib/server.py @@ -4,14 +4,18 @@ from typing import Callable def serve(address: str, port: int, callback: Callable, wrapper: Callable[[socket.socket], socket.socket] = lambda s: s) -> None: server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - try: - server_socket.bind((address, port)) - server_socket.listen(1) - server_socket = wrapper(server_socket) + while True: + try: + server_socket.bind((address, port)) + server_socket.listen(1) + server_socket = wrapper(server_socket) - while True: - conn, addr = server_socket.accept() - client_connection = threading.Thread(target=callback, args=(conn, addr)) - client_connection.start() + while True: + conn, addr = server_socket.accept() + client_connection = threading.Thread(target=callback, args=(conn, addr)) + client_connection.start() - finally: server_socket.close() + except Exception as e: + print(e) + + finally: server_socket.close() diff --git a/src/main.py b/src/main.py index d645147..15539bc 100644 --- a/src/main.py +++ b/src/main.py @@ -22,7 +22,7 @@ def handle_client(client: socket.socket, addr: Tuple[str, int]) -> None: .send(client) def main() -> None: - http_thread = threading.Thread(name='http', target=serve, args=('0.0.0.0', 5000, handle_client)) + http_thread = threading.Thread(name='http', target=serve, args=('0.0.0.0', 6000, handle_client)) https_thread = threading.Thread(name='https', target=serve, args=('0.0.0.0', 6001, handle_client), kwargs=dict(wrapper=lambda socket: [ ctx:=ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER), ctx.load_cert_chain(certfile='./badcert.pem', keyfile='./badkey.pem'), @@ -30,8 +30,8 @@ def main() -> None: ][-1] )) - http_thread.start() - #https_thread.start() + #http_thread.start() + https_thread.start() if __name__ == '__main__': main()