Basically, I know that 'socket.io' is a one-on-one communication between the server and the client.
But when I tried to do it myself, it wasn't
- Connect to the socket using a chrome browser.
- Connect to the same page using the secret tab.
in the same situation as described above If an event occurs on client 1, it works on client 2.
How can I generate an event only on each client?
I connected different rooms to each client.
//server
socket.join(`${socket.id}`)
socket.to(`${socket.id}`).emit('event')
It will not work anywhere.
CodePudding user response:
This method:
socket.to(room).emit(...)
sends to all sockets in the room EXCEPT the one represented by socket
.
If you want to send to everyone in the room, then use this:
io.to(room).emit(...)