From ead1790c206828b6f72f3b07bd6a0dbd11a1eb64 Mon Sep 17 00:00:00 2001 From: mivirl <> Date: Fri, 26 Jan 2024 09:24:54 -0600 Subject: [PATCH] Retry connection to server --- src/client.pl | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/client.pl b/src/client.pl index 2be77db..7656540 100644 --- a/src/client.pl +++ b/src/client.pl @@ -63,7 +63,14 @@ sub connect_to_server { PeerPort => $port, Proto => 'tcp' ); - $socket || die "Failed to connect: $!"; + my $wait = 1; + while ((! $socket) && $wait < 16) { + sleep $wait; + $wait *= 2; + } + if ($wait >= 16) { + die "Failed to connect to $server_ip:$port : $!"; + } $socket->autoflush(1); return $socket; } -- 2.39.5