Wednesday, 30 March 2016

how to fix org.java_websocket.exceptions.WebsocketNotConnectedException



if you see this error:

org.java_websocket.exceptions.WebsocketNotConnectedException
 at org.java_websocket.WebSocketImpl.send(WebSocketImpl.java:566)
 at org.java_websocket.WebSocketImpl.send(WebSocketImpl.java:543)
 at org.java_websocket.client.WebSocketClient.send(WebSocketClient.java:171)
 at com.github.nkzawa.engineio.client.transports.WebSocket$2.call(WebSocket.java:114)
 at com.github.nkzawa.engineio.parser.Parser.encodePacket(Parser.java:63)
 at com.github.nkzawa.engineio.parser.Parser.encodePacket(Parser.java:42)
 at com.github.nkzawa.engineio.client.transports.WebSocket.write(WebSocket.java:110)
 at com.github.nkzawa.engineio.client.Transport$3.run(Transport.java:98)
 at com.github.nkzawa.thread.EventThread.exec(EventThread.java:50)
 at com.github.nkzawa.engineio.client.Transport.send(Transport.java:94)
 at com.github.nkzawa.engineio.client.Socket$7$1$1.run(Socket.java:344)
 at com.github.nkzawa.engineio.client.transports.Polling$1$1.run(Polling.java:49)
 at com.github.nkzawa.engineio.client.transports.Polling$1$2.call(Polling.java:64)
 at com.github.nkzawa.emitter.Emitter$OnceListener.call(Emitter.java:164)
 at com.github.nkzawa.emitter.Emitter.emit(Emitter.java:117)
 at com.github.nkzawa.engineio.client.transports.Polling._onData(Polling.java:137)
 at com.github.nkzawa.engineio.client.transports.Polling.onData(Polling.java:104)
 at com.github.nkzawa.engineio.client.transports.PollingXHR$5$1.run(PollingXHR.java:113)
 at com.github.nkzawa.thread.EventThread$2.run(EventThread.java:75)
 at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
 at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
 at java.lang.Thread.run(Thread.java:841)

You will have no idea why your app crashed, and this error trace gives no clue.

Actually it is Socketio error, you can fix it by setting okhttp as the client:


https://github.com/socketio/socket.io-client-java/issues/68



How:

I used to use:

compile 'com.github.nkzawa:socket.io-client:0.3.0'

To fix this I did this:

compile ('io.socket:socket.io-client:0.7.0') {
    // excluding org.json which is provided by Android    exclude group: 'org.json', module: 'json'}

Note:

This lib's source code is used to under nkzawa's personal project, and packages are com.github.nkzawa.*.

nkzawa is still the author of the latest code, but he has moved it to socket.io's repo and package nams were changed, so if you used to use 0.3.0, after you changed to 0.7.0 you should change package name in your code, you don't need to change your code. (just change import, your IDE will tell you)


No comments:

Post a comment