4

I want to callback the server to ack that my client has received a call. In the opposite direction, this is heavily documented and working fine, but how can I ack from the client?

NB: I am using socket-io-java-client https://github.com/socketio/socket.io-client-java on Android, not JavaScript, but it shouldn't matter. Well, maybe it does.

    socket.on("onMessage", new Emitter.Listener() {
                @Override public void call(Object... args) {
                    // I have the args here and the last argument is a callback,
                    // but what do I need to do to callback the server using that arg?
                }
            })

In Swift it looks like this, but I can't figure out how to do this in Java with the above mentioned library.

    socket.on("onMessage") { data, ack in
        ack?()
    }

Has anybody done this or knows how to achieve that?

Oliver Hausler
  • 4,900
  • 4
  • 35
  • 70
  • just a comment, but these messages are sent on top of TCP. You will have already known that the message is received. – Paul Nikonowicz Oct 08 '15 at 17:02
  • @PaulNikonowicz Why do we have an ack in the other direction? Are client-to-server emits sent as UDP? What is the logic why we have an "official" ack on the server-side, but not on the client-side? – Oliver Hausler Oct 08 '15 at 18:13

1 Answers1

7

I overlooked this. There is an example posted here:

https://github.com/socketio/socket.io-client-java

// ack from client to server
socket.on("foo", new Emitter.Listener() {
  @Override
  public void call(Object... args) {
    Ack ack = (Ack) args[args.length - 1];
    ack.call();
  }
});

[Credits go to Alex who just skyped me the URL.]

Oliver Hausler
  • 4,900
  • 4
  • 35
  • 70