fix some of the things
This commit is contained in:
parent
a77e8f1f73
commit
d7bc8243e8
@ -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
|
||||
'';
|
||||
}
|
||||
|
@ -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()
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user