Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

detect if socket.io emit did not work

How can i detect if a message did not reach my node.js+socket.io server. I have an emit from the server for message sent success.

socket.on('message', function(msg) {
var sendersusername = msg.source;
if (io.sockets.sockets[socket.id] != undefined)
{
  io.sockets.sockets[socket.id].emit('messagesentsuccess',
               {"user": msg.target,
               "message":msg.message
                 });
}
});

from this code i get a success message when a message reaches the server. How do i know if the message could not be sent to the server?

like image 906
user3455531 Avatar asked Jun 30 '14 20:06

user3455531


1 Answers

you can use

socket.on('error', function (err) {
    console.log(err);
});

to detect errors`

like image 171
vipulsodha Avatar answered Oct 16 '22 07:10

vipulsodha