socket.io-client-cpp icon indicating copy to clipboard operation
socket.io-client-cpp copied to clipboard

call ACK when receive message

Open whatisor opened this issue 3 years ago • 3 comments

Hi it seems to be no way to call ack when receive message sio::socket::event_listener_aux([&](string const& name, message::ptr const& data, bool isAck, message::list& ack_resp)

what is ack_resp for? It suppose to be a function to call instead of message

whatisor avatar Dec 29 '21 01:12 whatisor

this is how java implement ack.

            public void call(final Object... args) {
                EventThread.exec(new Runnable() {
                    public void run() {
                        if (!sent[0]) {
                            sent[0] = true;
                            Socket.logger.fine(String.format("sending ack %s", args.length != 0 ? args : null));
                            int type = HasBinary.hasBinary(args) ? 6 : 3;
                            Packet<JSONArray> packet = new Packet(type, new JSONArray(Arrays.asList(args)));
                            packet.id = id;
                            Socket.this.packet(packet);
                        }
                    }
                });
            }

Need to find out

whatisor avatar Dec 29 '21 14:12 whatisor

I got it worked by this:

packet p(packet::type_ack); send_packet(p);

this works as Ack.call() of java

whatisor avatar Dec 29 '21 15:12 whatisor

Hi, I'm having the same issue: I just want to send response on a request. Can you please extend your solution?

mdblabs avatar Aug 27 '22 19:08 mdblabs