Java – how to use callback on socket.io client?

I want to call back to the server to confirm that my client has received the call. In the opposite direction, this has been heavily recorded and works normally, but how should I confirm to the client?

Note: I use socket IO java client on Android instead of JavaScript https://github.com/socketio/socket.io-client-java , but it doesn'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?
                }
            })

It looks like this in swift, but I can't figure out how to use the above library to do this in Java

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

Does anyone do this or know how to do it?

resolvent:

I ignored this point. Here is an example:

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();
  }
});

[credit goes to Alex, who just makes my URL blank

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>