Detect if socket.io emit is not working

How can I determine if a message has reached my server node.js + socket.io. I have an emission from the server to send a message successfully.

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 the message reaches the server. How do I know if a message could be sent to the server?

+4
source share
1 answer

you can use

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

to detect errors

+1
source

Source: https://habr.com/ru/post/1546617/


All Articles