diff --git a/src/main/java/org/java_websocket/client/WebSocketClient.java b/src/main/java/org/java_websocket/client/WebSocketClient.java
index 00e40fda..52dbe61e 100644
--- a/src/main/java/org/java_websocket/client/WebSocketClient.java
+++ b/src/main/java/org/java_websocket/client/WebSocketClient.java
@@ -38,6 +38,7 @@
import java.util.Collections;
import java.util.Map;
import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLException;
@@ -281,6 +282,20 @@ public boolean connectBlocking() throws InterruptedException {
return engine.isOpen();
}
+ /**
+ * Same as connect
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 connectBlocking(long timeout, TimeUnit timeUnit) throws InterruptedException {
+ connect();
+ return connectLatch.await(timeout, timeUnit) && engine.isOpen();
+ }
+
/**
* Initiates the websocket close handshake. This method does not block
* In oder to make sure the connection is closed use closeBlocking