Updating the event emitter

To send acknowledgement d=from server to client, we're going to add a third argument which is going to be a callback function. This function is going to fire when the acknowledgement arrives at the client, and we can do anything we like. For now we'll just print using console.log('Got it'):

socket.emit('createMessage', { 
  from: 'Frank', 
  text: 'Hi' 
}, function () { 
  console.log('Got it'); 
}); 

Now this is all we need to do bare-bones style to add an acknowledgement to the client.

Get Advanced Node.js Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.