2

I'm having trouble sending acknowledgements from my socket.IO server. I've followed the documentation and added a function "fn" to my message handler function. Unfortunately fn is undefined. What's wrong with my code?

socket.on('search', function (searchParamsFromClient, fn) {
Erik Z
  • 4,660
  • 6
  • 47
  • 74

1 Answers1

3

The function 'fn' needs to be defined on the other side of the socket, i.e., the client.

Server:

socket.on('search', function (searchParamsFromClient, ack) {
  // do something with searchParamsFromClient
  ack();
}

Client:

socket.emit('search', searchPayload, function() {
  // acknowledgement
  // This function is what gets called as ack()
});
vantony
  • 513
  • 6
  • 9