Looking at source.io source I found that ACKs are indeed supported for messages sent by the server (but not in transmissions!) (Lines 115-123 from socket.io/lib/socket.js):
if ('function' == typeof args[args.length - 1]) { if (this._rooms || (this.flags && this.flags.broadcast)) { throw new Error('Callbacks are not supported when broadcasting'); } debug('emitting packet with ack id %d', this.nsp.ids); this.acks[this.nsp.ids] = args.pop(); packet.id = this.nsp.ids++; }
An example of how ack should work (not tested):
// server-side: io.on('msg', (data, ackCallback) => { console.log('data from client', data); ackCallback('roger roger'); }); // client-side: socket.emit('msg', someData, (answer) => { console.log('server\ acknowledgement:', answer); });
source share