python-socketio asyncio client: Is it possible to know when emit is completelly send data over the wire to server?

Question:

Do python-socketio or underlying python-engineio have any kind of confirmation that specific message was completely delivered to other side, similar to what TCP does to ensure all data was successfully transferred to other side?

I have kind of pubsub service built on python-socketio server, which sends back ok/error status when request has been processed. But in my python-socketio client sometimes I just need fire and forget some message to pubsub but I have to wait it was completely delivired before I terminate my application.

So, my naive code:

await sio.emit("publish", {my message})

it seems the await above is just scheduling send over wire to asyncio, but does not wait for send to complete. I suppose it’s by design. Just need to know is it possible to know when send is complete or not.

Asked By: bialix

||

Answers:

Socket.IO has ACK packets that can be used for the receiving side to acknowledge receipt of an event.

When using the Python client and server, you can replace the emit() with call() to wait for the ack to be received. The return value of call() is whatever data the other side returned in the acknowledgement.

But not that for this to work the other side also needs to be expanded to send this ACK packets. If your other side is also Python, an event handler can issue an ACK simply by returning something from the handler function. The data that you return is included in the ACK packet. If the other side is JavaScript, you get a callback function passed as a last argument into your handler. The handler needs to call this function passing any data that it wants to send to the other side as response.

Answered By: Miguel Grinberg