This commit is contained in:
N0\A
2025-10-24 14:29:04 +02:00
parent 3b6b40fa88
commit b9e2da327a
2 changed files with 157 additions and 148 deletions

View File

@@ -46,6 +46,7 @@ class DuktoProtocol:
self.on_send_complete: Optional[Callable[[List[str]], None]] = None
self.on_transfer_progress: Optional[Callable[[int, int], None]] = None
self.on_error: Optional[Callable[[str], None]] = None
self.on_incoming_connection: Optional[Callable[[str, socket.socket], None]] = None
def set_ports(self, udp_port: int, tcp_port: int):
self.local_udp_port = udp_port
@@ -192,11 +193,21 @@ class DuktoProtocol:
conn.close()
continue
threading.Thread(target=self._receive_files,
args=(conn, addr[0]), daemon=True).start()
if self.on_incoming_connection:
# Pass the connection to the handler to decide
self.on_incoming_connection(addr[0], conn)
else:
# Auto-reject if no handler is set
conn.close()
except Exception as e:
if self.running:
print(f"TCP listener error: {e}")
def start_receiving(self, conn: socket.socket, sender_ip: str):
"""Starts the receiving process on an already accepted connection."""
threading.Thread(target=self._receive_files,
args=(conn, sender_ip), daemon=True).start()
def _receive_files(self, conn: socket.socket, sender_ip: str):
self.is_receiving = True