Socket.io client on Google Glass

淺唱寂寞╮ 提交于 2019-12-08 03:29:53

问题


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 Im 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 doesnt seem to trigger any of the ConnectCallback functions on my Google Glass.

Here is the code Im 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" function, 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


回答1:


I was facing the same issue here and noticed although my Glass showed it was connected to my Wifi network, it actually wasn't. I tried adb shell netcfg on it and to my surprise the wlan0 interface had no IP assigned. I reconnected it to the wifi network again and it all started to work just fine.

The weird thing though is that I was expecting some sort of error to be logged (even though I was using a different Socket.IO client). I believe the case to be a timeout that didn't expire (connection/socket timeout) so it was still attempting to connect and didn't fail in time for us to see the log entry. I guess these libraries have a relatively high connection timeout set by default, so you wouldn't see an error before many seconds would go by.



来源:https://stackoverflow.com/questions/26407781/socket-io-client-on-google-glass

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