From df7f9b77f45cf3c2099dac44e6be8c116d8c55f1 Mon Sep 17 00:00:00 2001 From: Chintan Patel Date: Sat, 14 Sep 2024 03:16:46 -0500 Subject: [PATCH] Updated onClose Subscription websocket so it can reconnect when connection is closed --- .../p2p/solanaj/ws/SubscriptionWebSocketClient.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/p2p/solanaj/ws/SubscriptionWebSocketClient.java b/src/main/java/org/p2p/solanaj/ws/SubscriptionWebSocketClient.java index 875b9088..608c8cc4 100644 --- a/src/main/java/org/p2p/solanaj/ws/SubscriptionWebSocketClient.java +++ b/src/main/java/org/p2p/solanaj/ws/SubscriptionWebSocketClient.java @@ -251,7 +251,15 @@ public void onMessage(String message) { public void onClose(int code, String reason, boolean remote) { System.out.println( "Connection closed by " + (remote ? "remote peer" : "us") + " Code: " + code + " Reason: " + reason); - + try { + boolean connected = reconnectBlocking(); + while (!connected) { + Thread.sleep(1000); + connected = reconnectBlocking(); + } + } catch (InterruptedException e) { + throw new RuntimeException(e); + } } @Override