Question

I've been working with using socket.io with Android for a few days now. As of now, I am using AndroidAsync by Koush. When I try to connect to my local socket.io server (http://192.168.2.1:3000) everything is okay, I can emit commands and receive event messages. But when I try to use it to a live server with query string parameters (http://api.mysite.com:8000/socket.io/1?v=1&name=xxx&password=xxx) I cannot get to connect. Is there a proper way of passing query strings parameter to AndroidAsync socket.io? Here is my code.

    Uri.Builder b = Uri.parse("http://api.mysite.com:8000/socket.io/1").buildUpon();
    b.appendQueryParameter("v", "1");
    b.appendQueryParameter("name", "xxx");
    b.appendQueryParameter("pass", "xxx");

    myUrl = b.build().toString();

    AsyncHttpClient.getDefaultInstance().getString(myUrl, new AsyncHttpClient.StringCallback() {

            @Override
            public void onCompleted(Exception arg0, AsyncHttpResponse arg1, String arg2) {
                // TODO Auto-generated method stub

            }

            @Override
            public void onConnect(AsyncHttpResponse response) {
                // TODO Auto-generated method stub
                super.onConnect(response);
                Log.d("tag","onConnect!");
            }

            @Override
            public void onProgress(AsyncHttpResponse response, int downloaded,
                    int total) {
                // TODO Auto-generated method stub
                super.onProgress(response, downloaded, total);
                Log.d("tag","Progress!");
            }


        });

        SocketIOClient.connect(AsyncHttpClient.getDefaultInstance(), myUrl, new ConnectCallback() {

            @Override
            public void onConnectCompleted(Exception arg0, SocketIOClient client) {
                // TODO Auto-generated method stub
                if (client.isConnected()) {
                    Log.d("tag","!");
                } else {
                    Log.d("tag","?");
                }


            }
        });
Was it helpful?

Solution

I found this same issue in his other library android-websockets. I helped him fix it in both of his projects. Check out the changes made to AndroidAsync and android-websockets. The link to the android-websockets describes the problem in detail. I suggest you pull the latest changes in from the master branch and try again.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top