K
K
Konstantin2019-01-19 01:39:17
Node.js
Konstantin, 2019-01-19 01:39:17

How to send message to specific user from Node.js socket server?

I'm using websockets to create a server socket in Node.js

I've read the documentation but one question remains:

How to send a message to a specific connected user? Now all samples are about the general message.

As far as I know I need to create a channel with a unique name for each user on the server and then on the client link them to receive messages?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Anton Shvets, 2019-01-20
@Junart1

And how do you manage to send a websocket message NOT to a specific user? The protocol is designed as a point-to-point exchange. You only need to learn how to distinguish between these users.
To do this, when establishing a connection, you need to receive some data for authorization (for example, a token or session ID), and keep a connection pool in which, if necessary, you can find the connection of the desired user.

P
ProAI, 2020-01-15
@ProAI

Since you have the SOCKET.IO tag in your question , it is obvious that you have it in Node.js and is spinning,
respectively, you should refer to the official documentation , and in short:
socket.emit('hello', 'world');

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question