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 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
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 >
Original file line number Diff line number Diff line change 22
33import java .io .IOException ;
44import java .net .URI ;
5+ import java .nio .ByteBuffer ;
56import java .time .Duration ;
67import java .util .List ;
78import 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+
7287public void send (String message ) {
7388Session s = awaitOpen (Duration .ofMillis (5000L ));
7489try {
Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ public WebsocketEndpoints(WebsocketConnection client) {
2020@ Override
2121public void onOpen (Session session , EndpointConfig config ) {
2222client .sessionReady ().complete (session );
23+ session .setMaxIdleTimeout (0L );
2324log .info ("Connected to server" );
2425if (client .onOpenHandler () != null ) {
2526try {
You can’t perform that action at this time.
0 commit comments