简体   繁体   中英

Android socket connection using socket.io 0.9.0 version

I am facing issue with connecting to the socket server. I am currently working on an android project, In this project, I need to connect the socket server in the application. I am currently referring ios application code so that it's easy to build android version app. Ios is connecting successfully to that socket connect but with the same URL and version android doesn't.

Here what i have done till today:

 IO.Options opts = new IO.Options();
    opts.secure = true;
    try {
        socket = IO.socket("http://host.com:7000/chat", opts);
    } catch (URISyntaxException e) {
        e.printStackTrace();
    }

    socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() {

        @Override
        public void call(Object... args) {
            socket.emit("foo", "hi");
            socket.disconnect();
        }

    }).on("event", new Emitter.Listener() {

        @Override
        public void call(Object... args) {
        }

    }).on(Socket.EVENT_DISCONNECT, new Emitter.Listener() {

        @Override
        public void call(Object... args) {
            Log.d("LOG", "disconnect: ");
        }

    }).on(Socket.EVENT_ERROR, new Emitter.Listener() {
        @Override
        public void call(Object... args) {
            Log.d("LOG", "Error: ");
        }
    });
    socket.connect();

It doesn't work.

Here is IOS swift code:

var socketIO : SocketIO!
    socketIO = SocketIO.init(delegate: self as SocketIODelegate)
    socketIO?.useSecure = true
    socketIO.connect(toHost: "host.com", onPort: 7000, withParams: nil, withNamespace: "/chat")

It's connecting successfully.

I don't know why it's not connecting on the android side with the same version of the library.

Can anyone have an idea about this?

** Note: Server-side has 0.9 version of socket.io SDK.**

Refer this github repository and I only can find this github repository that can work for socket 0.9 version.

It may help you.

Happy coding :)

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