简体   繁体   中英

Connection problems with the socket.io-client to socket.io server 0.9.6

I have a problem with my socket.io code for android.

The Server uses socket.io 0.9.6 On android I'm using socket-io-client-0.1.3.jar and engine-io-client.0.2.3.jar from nkzawa

After the connection to myChannel a myConnect is emitted. Afterwards I always get a "something_changed" message if something changes with the new values. My version in js works fine, but on android I only get:

EVENT_CONNECT_ERROR: com.github.nkzawa.engineio.client.EngineIOException: xhr poll error

Any ideas how to fix it?

socket = IO.socket(WEBSOCKET + "myChannel");
socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() {
    @Override
    public void call(Object... args) {
        socket.emit("myConnect", userinfo);
    }
    }).on(Socket.EVENT_CONNECT_ERROR, new Emitter.Listener() {
    @Override
    public void call(Object... arg0) {
        Log.e("EVENT_CONNECT_ERROR", arg0[0].toString());
    }
    }).on("something_changed", new Emitter.Listener() {
    @Override
    public void call(Object... args) {
        JSONObject obj = (JSONObject) args[0];
        Log.i("something_changed", obj.toString());
    }
});
socket.connect();

I faced the same issue. It was causing because of the internet access permission.

Add internet permission in your manifest.

<uses-permission android:name="android.permission.INTERNET" ></uses-permission>

It should work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM