I try to use AndroidAsync library. Here is a code sample:
AsyncHttpClient.getDefaultInstance()
.websocket(url, null, new AsyncHttpClient.WebSocketConnectCallback() {
@Override
public void onCompleted(Exception ex, WebSocket webSocket) {
Log.i(LOG_TAG, "onCompleted");
if (ex != null) {
Log.e(LOG_TAG, "ex != null");
Log.e(LOG_TAG, ex.toString());
ex.printStackTrace();
return;
}
if (webSocket == null) {
Log.e(LOG_TAG, "1 webSocket == null");
} else {
Log.w(LOG_TAG, "1 webSocket != null");
}
webSocket.setStringCallback(new WebSocket.StringCallback() {
public void onStringAvailable(String s) {
Log.i(LOG_TAG, "setStringCallback");
System.out.println("I got a string: " + s);
}
});'
In my case ex == null but webSocket == null. The nullpointerexception is caught inside the library code. But can I use this socket? It looks strange that it is null even when there is no exception in the callback.