Getting the Reason Why Websockets Closed With Close Code 1006

1006 Connection closed abnormally error with python 3.7 websockets

So I found the solution:

When the connection closes, it breaks out of the while loop for some reason. So in order to keep the websocket running you have to surround

resp = await websocket.recv()

with try ... except and have

print('Reconnecting')
websocket = await websockets.connect(ws_url)

in the exception handling part.

Websocket closed code: 1006 Node Android okhttp3 AmazonEc2

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() {
public void run() {

// Poplulate the recycler view here....

}


Related Topics



Leave a reply



Submit