From 413eb798d67dd153040d4112f1259198069016ad Mon Sep 17 00:00:00 2001 From: harlekin <5800926-mw102@users.noreply.gitlab.com> Date: Sat, 19 Feb 2022 14:58:25 +0000 Subject: [PATCH] improved logging for ping --- src/com/sheepit/client/Speedtest.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/com/sheepit/client/Speedtest.java b/src/com/sheepit/client/Speedtest.java index dace61d..505f18c 100644 --- a/src/com/sheepit/client/Speedtest.java +++ b/src/com/sheepit/client/Speedtest.java @@ -125,14 +125,16 @@ public class Speedtest { } private static int ping(String url, int port) { + InetAddress mirrorIP = null; try (Socket socket = new Socket()) { - InetAddress mirrorIP = InetAddress.getByName(new URL(url).getHost()); + mirrorIP = InetAddress.getByName(new URL(url).getHost()); SocketAddress socketAddress = new InetSocketAddress(mirrorIP, port); int maxWaitingTime_ms = 3000; socket.connect(socketAddress, maxWaitingTime_ms); } catch (IOException e) { - throw new RuntimeException("Unable to connect to " + url + ":" + port, e); + String problemURL = mirrorIP != null ? mirrorIP + " (derived from: " + url + ")" : url; + throw new RuntimeException("Unable to connect to " + problemURL, e); } return -1; }