File tree Expand file tree Collapse file tree 1 file changed +15
-0
lines changed
src/main/java/org/java_websocket/client Expand file tree Collapse file tree 1 file changed +15
-0
lines changed Original file line number Diff line number Diff line change 38
38
import java .util .Collections ;
39
39
import java .util .Map ;
40
40
import java .util .concurrent .CountDownLatch ;
41
+ import java .util .concurrent .TimeUnit ;
41
42
42
43
import javax .net .ssl .SSLContext ;
43
44
import javax .net .ssl .SSLException ;
@@ -281,6 +282,20 @@ public boolean connectBlocking() throws InterruptedException {
281
282
return engine .isOpen ();
282
283
}
283
284
285
+ /**
286
+ * Same as <code>connect</code> but blocks with a timeout until the websocket connected or failed to do so.<br>
287
+ * @param timeout
288
+ * The connect timeout
289
+ * @param timeUnit
290
+ * The timeout time unit
291
+ * @return Returns whether it succeeded or not.
292
+ * @throws InterruptedException Thrown when the threads get interrupted
293
+ */
294
+ public boolean connectBlocking (long timeout , TimeUnit timeUnit ) throws InterruptedException {
295
+ connect ();
296
+ return connectLatch .await (timeout , timeUnit ) && engine .isOpen ();
297
+ }
298
+
284
299
/**
285
300
* Initiates the websocket close handshake. This method does not block<br>
286
301
* In oder to make sure the connection is closed use <code>closeBlocking</code>
You can’t perform that action at this time.
0 commit comments