3

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.

Sergey Novikov
  • 381
  • 3
  • 4

2 Answers2

1

If the server you're connecting to rejects the connection with a response code (HTTP style ie. 405). Then the server is essentially closing the connection during the attempted connect.

This is does not throw an exception because there was no Timeout, or Network Issue. Furthermore, there is no websocket returned because the server did not allow the connection to be established.

bleuf1shi
  • 830
  • 7
  • 12
0

I had the same problem one of these solve that. if you use XAMPP start both Apache and Tomcat. export your server project in war file when you define the Tomcat version which you have in your system. Check sensitively the port and ip you choose for websocket.

Mohad Hadi
  • 1,826
  • 3
  • 24
  • 39