import socket, threading, datetime

def log(msg):
    print(f"[{datetime.datetime.now().strftime('%H:%M:%S')}] {msg}", flush=True)

def handle(conn, addr):
    log(f"CONEXAO em 10001 de {addr}")
    try:
        conn.settimeout(5)
        data = conn.recv(4096)
        log(f"dados recebidos: {len(data)} bytes: {data[:80]!r}")
    except Exception as e:
        log(f"sem dados / erro: {e}")
    finally:
        conn.close()

srv = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
srv.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
srv.bind(("0.0.0.0", 10001))
srv.listen(5)
log("probe escutando em 0.0.0.0:10001")
while True:
    conn, addr = srv.accept()
    threading.Thread(target=handle, args=(conn, addr), daemon=True).start()
