Answer the question
In order to leave comments, you need to log in
How to send Socket.io events to a specific user?
Greetings, I recently started learning the node and got to the sockets.
What I want to do: an application that sends individual events to users.
They must be identified by the token from the URL. So, how to send each user their events?
For example: to the user with url localhost?token=1 - send “Hi”, and to the user localhost?token=2 - “Hi, how are you?”.
I know that the socket assigns its own id to each new user, but I need a token to compare the user with the database.
Vooshche, it is possible to implement?
Answer the question
In order to leave comments, you need to log in
When a logged in user connects, we need to store the connection identifier somewhere. It can be in the database or, for example, in Redis. We must forget that one user can have as many connections as he wants and from any number of devices. Therefore, they usually use more queues and subscribe to messages from queues tagged with the user's Id.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question