Android SDK WebsocketNotConnectedException

We have integrated and published an Android app with WCS Android SDK. We get the following exception in our crashlytics logs. Not able to understand what part of our code is throwing this exception and why

org.java_websocket.exceptions.WebsocketNotConnectedException
at org.java_websocket.WebSocketImpl.send(WebSocketImpl.java:573)
at org.java_websocket.WebSocketImpl.send(WebSocketImpl.java:550)
at org.java_websocket.client.WebSocketClient.send(WebSocketClient.java:145)
at com.flashphoner.fpwcsapi.ws.WebSocketChannelClient$2.run(WebSocketChannelClient.java:116)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:224)
at com.flashphoner.fpwcsapi.util.LooperExecutor.run(LooperExecutor.java:44)
 

Max

Administrator
Staff member
Good day.
org.java_websocket.exceptions.WebsocketNotConnectedException
This means application cannot establish websocket connection to WCS. Please check if WCS server you're trying to connect to is up and running, and Websocket ports 8080 and 8443 is not blocked.
 
This error is very intermittent and doesn't happen to everyone. The app crashes after this error. Is there any way to catch this error and show appropriate message instead of app crashing.
 

Max

Administrator
Staff member
Is there any way to catch this error and show appropriate message instead of app crashing.
You can wrap websocket session establishing to try-catch, for example
Java:
try {
    session = Flashphoner.createSession(sessionOptions);
} catch (WebsocketNotConnectedException e) {
    mPublishStatus.setText("Websocket connection failed")
}
 
Last edited:

mbedial

Member
Hi,

Same failure here. We have tried the createSessions try/catch approach but we have still the same crash in some of our users. If this is a connectivity error we want also to show a message and retry later. Is there any other actions we can do in order to be crash free?
 

Max

Administrator
Staff member
Please check if this crash related to this your topic.
Also, please check if the issue is reproducing in Phone Min example, Streaming-min example and so on. If not, modify example code minimally to reproduce the issue and send the code using this from.
 

mbedial

Member
No it is not related and there is not an example code to reproduce because it is happening only in 0.1% of our users.
 

Max

Administrator
Staff member
We have tried the createSessions try/catch approach but we have still the same crash in some of our users
You should wrap Session.connect() in try/catch because the connection is establishing in this method, not in Flashphoner.createSession() method.
No it is not related and there is not an example code to reproduce because it is happening only in 0.1% of our users.
Unfortunately, we cannot fix neither symptoms nor reason if there is no consistent reproduction.
 

mbedial

Member
Session.connect() it is not in the stack trace of

1627552897211.png

Would be usefull to try/catch it?

In this class (WebSocketChannelClient.java:120) there is a disconnect() method:

1627553042790.png


that ends calling execute method via Looper:

1627553351650.png


And there is where is called send() method from WebSocketClient. Following it we can see that it can throw WebsocketNotConnectedException:

1627553488073.png


It throws an Exception but following back nowhere is catched. Would be possible to catch it and call the onDisconnection callback?
 

Max

Administrator
Staff member
We raised the tickect WCS-3273 to implement this. Will let you know here.
As workaround, you can wrap every stream operation (publish/play/stop) in try/catch to catch this exception, because all the actions requires Websocket messaging, so this exception can be thrown everywhere.
 

mbedial

Member
Hi!

Thanks for your effort. Do we need to do something? How can we can handle the exception? Does it calls onDisconnection callback every time the connection gets down?
 

Max

Administrator
Staff member
Hello

Yes. Fix will be ported to 1.0 in the ticket WCS-3293
We will report once it is done.
 

Max

Administrator
Staff member
Thanks for your effort. Do we need to do something? How can we can handle the exception? Does it calls onDisconnection callback every time the connection gets down?
Yes, onDisconnected will be called if exception is catched, or if connection is closed by other side (for example, if TCP packet is rejected).
Sorry, one more question. Are you going to fix it in 1.0.1.* versions?
The issue was fixed in Android SDK 1.0 build 1.0.1.84. Please update and check.
 
Top