Skip to content

Commit 55d533d

Browse files
committed
update
1 parent 5c0aa02 commit 55d533d

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
<modelVersion>4.0.0</modelVersion>
1212
<artifactId>websocket-client</artifactId>
13-
<version>1.0.13</version>
13+
<version>1.0.14</version>
1414
<name>WebsocketClient</name>
1515
<packaging>jar</packaging>
1616

@@ -25,7 +25,7 @@
2525
<dependency>
2626
<groupId>info.unterrainer.commons</groupId>
2727
<artifactId>oauth-token-manager</artifactId>
28-
<version>1.0.7</version>
28+
<version>1.0.10</version>
2929
</dependency>
3030
<dependency>
3131
<groupId>info.unterrainer.commons</groupId>

src/main/java/info/unterrainer/websocketclient/WebsocketConnection.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.io.IOException;
44
import java.net.URI;
5+
import java.nio.ByteBuffer;
56
import java.time.Duration;
67
import java.util.List;
78
import java.util.Map;
@@ -69,6 +70,20 @@ public Session awaitOpen(Duration timeoutInMillis) {
6970
}
7071
}
7172

73+
/**
74+
* Sends a ping message to the server to keep the connection alive.
75+
*/
76+
public void sendPing() {
77+
Session s = awaitOpen(Duration.ofMillis(5000L));
78+
try {
79+
s.getBasicRemote().sendPing(ByteBuffer.allocate(1));
80+
} catch (Exception e) {
81+
log.error("Error sending ping: ", e);
82+
throw new WebsocketSendingMessageException(String.format("Failed to send ping."), e);
83+
}
84+
log.debug("Sent ping");
85+
}
86+
7287
public void send(String message) {
7388
Session s = awaitOpen(Duration.ofMillis(5000L));
7489
try {

src/main/java/info/unterrainer/websocketclient/WebsocketEndpoints.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public WebsocketEndpoints(WebsocketConnection client) {
2020
@Override
2121
public void onOpen(Session session, EndpointConfig config) {
2222
client.sessionReady().complete(session);
23+
session.setMaxIdleTimeout(0L);
2324
log.info("Connected to server");
2425
if (client.onOpenHandler() != null) {
2526
try {

0 commit comments

Comments
 (0)