koush AndroidAsync Socket.IO : Looks like ConnectCallback() is not triggered on Google Glass

流过昼夜 提交于 2019-12-11 03:48:48

问题


Im trying to let my Google Glass and my android phone connect to a NodeJs server that Im running on my computer, so that I can send messages from my android phone to my Google Glass.

For this I'm using koush's AndroidAsync library, which works great on my android phone and I have absolutely no trouble connecting my phone to the NodeJS server with this library.

However, the same code doesnt seem to work on my Google Glass. My Google Glass DOES connect, because the on connection EventHandler of my NodeJS server IS triggered, it just doesn't seem to trigger any of the ConnectCallback functions on my Google Glass.

Here is the code I'm using in my Google Glass app:

SocketIOClient.connect(AsyncHttpClient.getDefaultInstance(), "http://192.168.1.229:5000", new ConnectCallback() {
        @Override
        public void onConnectCompleted(Exception ex, SocketIOClient client) {
            Log.i("SOCKET", "CONNECTION COMPLETED");
            if (ex != null) {
                ex.printStackTrace();
                return;
            }

            client.setStringCallback(new StringCallback() {
                @Override
                public void onString(String string, Acknowledge acknowledge) {
                    Log.d("SOCKET", string);
                }
            });

            client.setJSONCallback(new JSONCallback() {
                @Override
                public void onJSON(JSONObject jsonObject, Acknowledge acknowledge) {
                    Log.d("SOCKET", jsonObject.toString());
                }
            });

            client.on("event", new EventCallback() {
                @Override
                public void onEvent(JSONArray jsonArray, Acknowledge acknowledge) {
                    Log.i("DATA: ", jsonArray.toString());
                    Gson gson = new Gson();
                }
            });
            mClient = client;
        }
    });
}

As you can see, Im trying to log "CONNECTION COMPLETED" in the onConnectCompleted method, but it never fires and nothing is ever logged.

I find this rather strange, as the same code DOES work on my android phone and "CONNECTION COMPLETED" IS logged when I run this bit of code on my android phone. The strangest thing is that my node server actually picks up the Google Glass as the on connection event is triggered on the server when my Glass connects.

So, can anybody help me find out why my Google Glass IS apparently connecting to my NodeJS server, but is NOT triggering any events when it connects. (Not triggering the ConnectCallback functions, "CONNECTION COMPLETED" is never logged)?

Thanks in advance,

Bram

来源:https://stackoverflow.com/questions/26370624/koush-androidasync-socket-io-looks-like-connectcallback-is-not-triggered-on

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!