While using Web3j websocket connection faced connection closed issue. After some time the connection was established and served few requests abruptly the connection closes.

Request you to share the way to reconnect WebSocket or any other better way to handle it.

Additionally, is it really required to explicitly invoke the connect() method of WebSocketService object?


WebSocketService ws = new WebSocketService("http://localhost:7081", false);
Admin web3Admin = web3Admin = Admin.build(ws);      


[ctReadThread-18] o.w.protocol.websocket.WebSocketClient   : Closed WebSocket connection to http://localhost:7082, because of reason: ''.Connection closed remotely: true

org.java_websocket.exceptions.WebsocketNotConnectedException: null
    at org.java_websocket.WebSocketImpl.send(WebSocketImpl.java:608) ~[Java-WebSocket-1.3.8.jar:na]
    at org.java_websocket.WebSocketImpl.send(WebSocketImpl.java:585) ~[Java-WebSocket-1.3.8.jar:na]
    at org.java_websocket.client.WebSocketClient.send(WebSocketClient.java:309) ~[Java-WebSocket-1.3.8.jar:na]
    at org.web3j.protocol.websocket.WebSocketService.sendRequest(WebSocketService.java:165) ~[core-4.1.1.jar:na]
    at org.web3j.protocol.websocket.WebSocketService.sendAsync(WebSocketService.java:154) ~[core-4.1.1.jar:na]
  • Shouldn't it be "ws://localhost:7081"? – goodvibration Apr 26 '19 at 18:42
  • Well I have tried the same as well but no difference. After catering few requests successfully, the connection closes abruptly after some time. – Geeky Researcher Apr 30 '19 at 3:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.