Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/main/java/org/java_websocket/client/WebSocketClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -281,6 +282,20 @@ public boolean connectBlocking() throws InterruptedException {
return engine.isOpen();
}

/**
* Same as <code>connect</code> but blocks with a timeout until the websocket connected or failed to do so.<br>
* @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<br>
* In oder to make sure the connection is closed use <code>closeBlocking</code>
Expand Down