diff --git a/examples/app/app.nim b/examples/app/app.nim index 361a2fb..114c239 100644 --- a/examples/app/app.nim +++ b/examples/app/app.nim @@ -166,10 +166,18 @@ proc punchHole(punchdConn: PunchdConnection, serverConn: ServerConnection, proc initServerConnection(serverHostname: string, serverPort: Port, probingPort: Port): Future[ServerConnection] {.async.} = - for i in 0 .. 1: + var failCount = 0 + while result.probedPorts.len < 2: # FIXME: error handling let sock = newAsyncSocket() - sock.bindAddr(probingPort) + try: + sock.bindAddr(probingPort) + except OSError as e: + if failCount == 3: + raise e + failCount.inc + await sleepAsync(1000) + continue await sock.connect(serverHostname, serverPort) let id = rand(uint32) await sock.send(&"get-endpoint|{id}\n")