0

I am using socket io for chatting but not able to send message to particular users message is sending to all users in group but i want to send message for a single specific user

any solutions for this

Send response to all clients except sender

Tried this link

socket.broadcast.emit('new message', { userId: userId, companyId: companyId, message: data }); });

1 Answers1

0

To send to a specific user use:

io.to(<socketid>).emit('new message', { userId, companyId, message: data });

For this to work you need to know the socketID of the user you want to send the message to.

You can get the socketID in your server like this:

io.on('connection', (socket) => {
  console.log(socket.id);
});
milo
  • 936
  • 7
  • 18