From 611d8977d2e957fdbf8c62f40257b09ed602585e Mon Sep 17 00:00:00 2001 From: Yuval Roth Date: Sat, 19 Apr 2025 16:37:07 +0300 Subject: [PATCH 1/2] Added reconnectBlocking overload that supports timeout in WebSocketClient.java --- .../org/java_websocket/client/WebSocketClient.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/main/java/org/java_websocket/client/WebSocketClient.java b/src/main/java/org/java_websocket/client/WebSocketClient.java index 1ac2df07..45e0246c 100644 --- a/src/main/java/org/java_websocket/client/WebSocketClient.java +++ b/src/main/java/org/java_websocket/client/WebSocketClient.java @@ -327,6 +327,20 @@ public boolean reconnectBlocking() throws InterruptedException { return connectBlocking(); } + /** + * Same as reconnect but blocks with a timeout until the websocket connected or failed + * to do so.
+ * + * @param timeout The connect timeout + * @param timeUnit The timeout time unit + * @return Returns whether it succeeded or not. + * @throws InterruptedException Thrown when the threads get interrupted + */ + public boolean reconnectBlocking(long timeout, TimeUnit timeUnit) throws InterruptedException { + reset(); + return connectBlocking(timeout, timeUnit); + } + /** * Reset everything relevant to allow a reconnect * From 3d8b96f48aeddc13e20c675328541b18a5321bdf Mon Sep 17 00:00:00 2001 From: Yuval Roth Date: Sat, 19 Apr 2025 17:12:27 +0300 Subject: [PATCH 2/2] Added since 1.6.1 in method doc --- src/main/java/org/java_websocket/client/WebSocketClient.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/org/java_websocket/client/WebSocketClient.java b/src/main/java/org/java_websocket/client/WebSocketClient.java index 45e0246c..0e38326d 100644 --- a/src/main/java/org/java_websocket/client/WebSocketClient.java +++ b/src/main/java/org/java_websocket/client/WebSocketClient.java @@ -335,6 +335,7 @@ public boolean reconnectBlocking() throws InterruptedException { * @param timeUnit The timeout time unit * @return Returns whether it succeeded or not. * @throws InterruptedException Thrown when the threads get interrupted + * @since 1.6.1 */ public boolean reconnectBlocking(long timeout, TimeUnit timeUnit) throws InterruptedException { reset();