web3j icon indicating copy to clipboard operation
web3j copied to clipboard

Fatal Exception: WebsocketNotConnectedException

Open milory13 opened this issue 4 years ago • 2 comments

Fatal Exception: WebsocketNotConnectedException

I implemented web3j for andrpoid library in my app(v.4.8.8-android). Sometimes my app crash with next stacktrace:

Fatal Exception: org.java_websocket.exceptions.WebsocketNotConnectedException at org.java_websocket.WebSocketImpl.send(WebSocketImpl.java:608) at org.java_websocket.WebSocketImpl.sendFrame(WebSocketImpl.java:634) at org.java_websocket.WebSocketImpl.sendPing(WebSocketImpl.java:641) at org.java_websocket.AbstractWebSocket$1.run(AbstractWebSocket.java:153) at java.util.TimerThread.mainLoop(Timer.java:562) at java.util.TimerThread.run(Timer.java:512)

Just web3j in my project used java_websocket. How to fix it issue?

Any version of Android

milory13 avatar Feb 01 '22 12:02 milory13

You likely have to connect to your websocket before using it in the constructor.

    static {
        WebSocketService ws = new WebSocketService("wss://....", false);
        try {
            ws.connect();
        } catch (ConnectException e) {
            e.printStackTrace();
        }

        web3j = Web3j.build(ws);
    }

caupcakes avatar Feb 09 '22 19:02 caupcakes

I can confirm, it can happen time to time after connection is established for 10-30mins not only on Android

ruXlab avatar Feb 28 '22 19:02 ruXlab

@milory13 there were a series of updates on on websockets. Please could you confirm if this happens also on current web3j-4.9.7?

gtebrean avatar Mar 08 '23 13:03 gtebrean

@gtebrean unfortunately today I use only local functional web3j, without connections to server

milory13 avatar Mar 08 '23 13:03 milory13

After several tests in my case is working so I\m closing this ticket. Feel free to reopen it if you spot it again on latest version.

gtebrean avatar Mar 08 '23 16:03 gtebrean