socket.io-client-cpp
socket.io-client-cpp copied to clipboard
How to send back acknowledge date / use message::list &ack_resp
Hi, When using a python socket.io client,when receiving a message, I could send back an acknowledge message (some Json).
In socket.io-client-cpp, the signature seems to enable it as well :
void bind_events()
{
current_socket->on("borobo.goto", sio::socket::event_listener_aux([&](string const& name, message::ptr const& data, bool isAck,message::list &ack_resp)
{
...
}
}
From the server side, acknowledge is asked for, so "isAck" is true. I spend a full day trying to find how to send some data back (I suppose I have to use ack_resp), but couldn't manage it. To be more precise, whatever I try to do, the server always get {"OK", true} (even if I don't write neither OK nor true in my code.
I would like, ideally, to be able send back a full Json (with 3 fields), or at least be able to send back a non-acknowledgment (for example {"OK", false}
Has one of you ever managed to send back aknoledgement with some data? If so, could you please share so code snippet? I couldn't find a single piece of code using ack_resp excepted one in chineese (https://blog.csdn.net/m0_37263637/article/details/78321560) which I didn't managed to get working either.
Thanks a lot in advance Best Felix
PS : a snippet of what I did in python :
@sio.on('test.goto',namespace='/test')
def on_message(data):
poi=data['poi'];
print('I received goto message : poi=', poi)
global robot_status
if(robot_status!='IDLE'):
dic={'error': True, 'message':'the robot is busy'}
print('ERROR : the robot can\'t accept POI because it is busy')
return dic
else
...
Try this
void bind_events()
{
current_socket->on("borobo.goto", sio::socket::event_listener_aux([&](string const& name, message::ptr const& data, bool isAck,message::list &ack_resp)
{
if (isAck) {
ack_resp.push("your data");
}
}
}
This is my first time commenting in github so im sorry if i made a mistake.
@Peanutzy what did you push into ack_resp for?