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 3838import java .util .Collections ;
3939import java .util .Map ;
4040import java .util .concurrent .CountDownLatch ;
41+ import java .util .concurrent .TimeUnit ;
4142
4243import javax .net .ssl .SSLContext ;
4344import javax .net .ssl .SSLException ;
@@ -281,6 +282,20 @@ public boolean connectBlocking() throws InterruptedException {
281282 return engine .isOpen ();
282283 }
283284
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+
284299 /**
285300 * Initiates the websocket close handshake. This method does not block<br>
286301 * 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