Changes to websocket

master
Jonttuuu 2023-07-30 15:34:07 +03:00
parent 76aad82883
commit 71b03cb87d
1 changed files with 12 additions and 5 deletions

View File

@ -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)