Random socket disconnection

Hi, I’m experiencing random disconnection when using my WSS infura node with Web3j:

org.java_websocket.exceptions.WebsocketNotConnectedException: org.java_websocket.WebSocketImpl.send(WebSocketImpl.java:608) org.java_websocket.WebSocketImpl.send(WebSocketImpl.java:585) atorg.java_websocket.client.WebSocketClient.send(WebSocketClient.java:309) org.web3j.protocol.websocket.WebSocketService.sendRequest(WebSocketService.java:235) org.web3j.protocol.websocket.WebSocketService.sendAsync(WebSocketService.java:186) org.web3j.protocol.core.Request.sendAsync(Request.java:91)

No idea why socket gets closed. Any suggestion?. Thank you

Welcome to the Infura Community @santamaria
Can you please share your code with us so we can try to help you debug this?

Hi Lily, thank you for your reply. It is sufficient a periodically get balance to the node.

Web3j web3 = Web3j.build(new WebSocketService(the_service, false));
CompletableFuture balance = web3.ethGetBalance(the_wallet, DefaultBlockParameterName.LATEST).sendAsync();
BigInteger amount = balance.get().getBalance();
System.out.println(amount);

After a random amount of time I receive: org.java_websocket.exceptions.WebsocketNotConnectedException