Skip to content Skip to sidebar Skip to footer

Websocket Closed Code: 1006 Node Android Okhttp3 Amazonec2

I am having an issue with Websocket ws is closed with code: 1006 reason: Environment Amazon EC2 Instance : t2.micro Ubuntu 18.04 Node : v12.16.3 Websocket : https://github.com/web

Solution 1:

The wierd part is that it was working once or twice before failing which was causing confusion. If it always failed and fave a logcat that would have been nice. The best way is to log all the possible errors/failures on server and client and see the message.

First Put The Log Inside On Failure

@Override
public void onFailure(@NotNull WebSocket webSocket, @NotNull Throwable t, okhttp3.@org.jetbrains.annotations.Nullable Response response) {
    super.onFailure(webSocket, t, response);

    Log.d("TAG", "websocket failure: " + t + response);
}

That gave the following message :

: `websocket failure: android.view.ViewRootImpl$CalledFromWrongThreadException: 
Only the original thread that created a view hierarchy can touch its views.null`

Then Wrap the popluation of recycler view in this

getActivity().runOnUiThread(new Runnable() {
publicvoidrun() {

  // Poplulate the recycler view here....

}

Post a Comment for "Websocket Closed Code: 1006 Node Android Okhttp3 Amazonec2"