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
24 changes: 22 additions & 2 deletions src/main/java/org/java_websocket/AbstractWebSocket.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ public abstract class AbstractWebSocket extends WebSocketAdapter {
*/
private int connectionLostTimeout = 60;

/**
* Attribute to keep track if the WebSocket Server/Client is running/connected
* @since 1.3.9
*/
private boolean websocketRunning = false;

/**
* Get the interval checking for lost connections
* Default is 60 seconds
Expand All @@ -87,11 +93,23 @@ public int getConnectionLostTimeout() {
public void setConnectionLostTimeout( int connectionLostTimeout ) {
this.connectionLostTimeout = connectionLostTimeout;
if (this.connectionLostTimeout <= 0) {
stopConnectionLostTimer();
if( WebSocketImpl.DEBUG )
System.out.println( "Connection lost timer stopped" );
cancelConnectionLostTimer();
return;
}
if (connectionLostTimer != null || connectionLostTimerTask != null) {
if (this.websocketRunning) {
if( WebSocketImpl.DEBUG )
System.out.println( "Connection lost timer restarted" );
//Reset all the pings
ArrayList<WebSocket> connections = new ArrayList<WebSocket>( getConnections() );
WebSocketImpl webSocketImpl;
for( WebSocket conn : connections ) {
if( conn instanceof WebSocketImpl ) {
webSocketImpl = ( WebSocketImpl ) conn;
webSocketImpl.updateLastPong();
}
}
restartConnectionLostTimer();
}
}
Expand All @@ -102,6 +120,7 @@ public void setConnectionLostTimeout( int connectionLostTimeout ) {
*/
protected void stopConnectionLostTimer() {
if (connectionLostTimer != null ||connectionLostTimerTask != null) {
this.websocketRunning = false;
if( WebSocketImpl.DEBUG )
System.out.println( "Connection lost timer stopped" );
cancelConnectionLostTimer();
Expand All @@ -119,6 +138,7 @@ protected void startConnectionLostTimer() {
}
if (WebSocketImpl.DEBUG)
System.out.println("Connection lost timer started");
this.websocketRunning = true;
restartConnectionLostTimer();
}

Expand Down