diff --git a/src/main/java/fi/flexplex/lib/WebSocketClient.java b/src/main/java/fi/flexplex/lib/WebSocketClient.java index 0d136f8..5eb7b46 100644 --- a/src/main/java/fi/flexplex/lib/WebSocketClient.java +++ b/src/main/java/fi/flexplex/lib/WebSocketClient.java @@ -1,6 +1,7 @@ package fi.flexplex.lib; import java.io.IOException; +import java.net.SocketException; import com.neovisionaries.ws.client.WebSocket; import com.neovisionaries.ws.client.WebSocketAdapter; @@ -19,11 +20,8 @@ public final class WebSocketClient { protected void connect() { if (!webSocket.isOpen()) { - try { - this.webSocket.connect(); - } catch (final WebSocketException e) { - flexLib.getLogger().warning("WebSocket connection to FlexPlex server failed."); - } + this.webSocket.connectAsynchronously(); + this.setWebSocketSettings(); } } @@ -31,6 +29,15 @@ public final class WebSocketClient { this.webSocket.disconnect(); } + private void setWebSocketSettings() { + try { + this.webSocket.getConnectedSocket().setSoTimeout(0); + this.webSocket.getConnectedSocket().setKeepAlive(true); + } catch (final SocketException | WebSocketException e) { + this.flexLib.getLogger().warning("Failed to set WebSocket settings"); + } + } + private WebSocket createWebSocket(final String url, final String token) throws IOException { return new WebSocketFactory() .createSocket(url)