Sending to individual socketid in Socket.IO

// sending to individual socketid (private message)
io.to(`${socketId}`).emit('hey', 'I just met you');

// WARNING: `socket.to(socket.id).emit()` will NOT work, as it will send to everyone in the room
// named `socket.id` but the sender. Please use the classic `socket.emit()` instead.

References
https://socket.io/docs/emit-cheatsheet/

One Comment on “Sending to individual socketid in Socket.IO”

  1. Hello! I used exactly the same code. But io didn’t emit the socket that i send.
    I used that way:
    io.to(`${socketId}`).emit(“output road”, { engineData: userdata })

    socketId is coming from the session and ‘output data’ is expecting front-end.

Comments are closed.