File tree Expand file tree Collapse file tree 3 files changed +18
-2
lines changed
src/main/java/info/unterrainer/websocketclient Expand file tree Collapse file tree 3 files changed +18
-2
lines changed Original file line number Diff line number Diff line change 10
10
11
11
<modelVersion >4.0.0</modelVersion >
12
12
<artifactId >websocket-client</artifactId >
13
- <version >1.0.13 </version >
13
+ <version >1.0.14 </version >
14
14
<name >WebsocketClient</name >
15
15
<packaging >jar</packaging >
16
16
25
25
<dependency >
26
26
<groupId >info.unterrainer.commons</groupId >
27
27
<artifactId >oauth-token-manager</artifactId >
28
- <version >1.0.7 </version >
28
+ <version >1.0.10 </version >
29
29
</dependency >
30
30
<dependency >
31
31
<groupId >info.unterrainer.commons</groupId >
Original file line number Diff line number Diff line change 2
2
3
3
import java .io .IOException ;
4
4
import java .net .URI ;
5
+ import java .nio .ByteBuffer ;
5
6
import java .time .Duration ;
6
7
import java .util .List ;
7
8
import java .util .Map ;
@@ -69,6 +70,20 @@ public Session awaitOpen(Duration timeoutInMillis) {
69
70
}
70
71
}
71
72
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
+
72
87
public void send (String message ) {
73
88
Session s = awaitOpen (Duration .ofMillis (5000L ));
74
89
try {
Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ public WebsocketEndpoints(WebsocketConnection client) {
20
20
@ Override
21
21
public void onOpen (Session session , EndpointConfig config ) {
22
22
client .sessionReady ().complete (session );
23
+ session .setMaxIdleTimeout (0L );
23
24
log .info ("Connected to server" );
24
25
if (client .onOpenHandler () != null ) {
25
26
try {
You can’t perform that action at this time.
0 commit comments