1

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

  • Could you specify if your Glass is directly connected to your Wifi network or if it's going through your phone's Bluetooth connection? – Alain Oct 17 '14 at 15:16
  • It's connected directly through wifi, but I managed to figure out what was going wrong. For some reason my install of ADT didn't show the logs, after restarting it a couple of times it works now! – Bram van der Giessen Oct 27 '14 at 22:47
  • possible duplicate of [koush AndroidAsync Socket.IO : Looks like ConnectCallback() is not triggered on Google Glass](http://stackoverflow.com/questions/26370624/koush-androidasync-socket-io-looks-like-connectcallback-is-not-triggered-on) – Anton Savin Nov 05 '14 at 12:10

1 Answers1

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.

Roberto Andrade
  • 1,793
  • 1
  • 21
  • 27