Handle Callbacks in Socket.io android client v1.4

Well. I finally figured that out on my own.

How do I handle the (Object... args) on the EVENT_CONNECT listener's callmethod?

I haven't yet figured that out. But I'm lookin.

What is a good minimum set of events that I can implement to be informed about the connection

These three methods would be sufficient :

connect : Fired upon a successful connection.
connect_error : Fired upon a connection error.
connect_timeout : Fired upon a connection timeout.

Source : Socket.io Docs

how am I supposed to process the (Object... args) on an emit acknowledgement?

So I was digging through the docs and found this :

Server (app.js)

var io = require('socket.io')(80);
  io.on('connection', function (socket) {
    socket.on('ferret', function (name, fn) {
      fn('woot');
    });
  });

Client

socket.on('connect', function () { // TIP: you can avoid listening on `connect` and listen on events directly too!
    socket.emit('ferret', 'tobi', function (data) {
      console.log(data); // data will be 'woot'
    });
  });

So the args will be whatever the server sent as parameter into the callback. So this is how you would write Java client code for the above server code :

public void call(Object... args) {
  String response = (String)args[0]; //this will be woot
}

The param can also be JSON, or any of the supported datatypes in socket.io :

we send a string but you can do JSON data too with the org.json package, and even binary data is supported as well!


No In Android its works like this

payload can be of JSONOBJECT/JSONArray

import com.github.nkzawa.socketio.client.Ack

socket.emit("EVENT_NAME", payload, Ack {
                    val ackData = it[0]
                    Logger.e(TAG, "ackData $ackData")

                })

server side

  socket.on('EVENT_NAME', (payload, callback) => {
   callback("success");
});