Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Check if the user received message with socket io

Check if the user received message with socket io

Problem

I have simple question , think I sent a Message with socket.emit in server to client , so how can I check if the user really got the message , does socket io or node have any built in system

, I know that I can use ping user with socket.emit and after that user send back a response that got server message , but I need to know does socket io have such bulit in system ?

thanks.

Problem courtesy of: Ata

Solution

Yes, you can do that by passing a function as the last parameter to .emit.

Example from the "Sending and getting data (acknowledgements)" section of socket.io:

server:

var io = require('socket.io').listen(80);

io.sockets.on('connection', function (socket) {
  socket.on('ferret', function (name, fn) {
    fn('woot');
  });
});

client:

Solution courtesy of: go-oleg

Discussion

View additional discussion.



This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

Check if the user received message with socket io

×

Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription

×