Jaswanth Kumar Jaswanth Kumar - 24 days ago 14
Javascript Question

Socket.emit with callback in Android - NodeJS

I'm trying to communicate with NodeJS server using SocketIO in Server and Android. Currently using Gottox SocketIO-Java-Client Repository

NODEJS:

socket.on('new user',function(data, callback){
if (nicknames.indexOf(data)!=-1){
callback(false);
} else{
callback(true);
socket.nickname = data;
nicknames.push(socket.nickname);
updateNicknames();
}
});


Android:

socket.emit("new user", "User01");


Now if I use the above code, callback error occurs at callback(true) as shown in the following link:
http://i.imgur.com/Hdn1yKQ.png

Please suggest on how to implement callbacks in Android.

Thanks!

Answer

Your Java client is not providing a callback. The client method should look like this:

socket.emit("new user", new IOAcknowledge() {
    public void ack(Object...args) {

    }
}, "User01");