0

In referrer to https://stackoverflow.com/questions/12246829/node-js-routing-data-with-socket-io

On client:

 // send data on some event socket.emit('send', { u: user_id, a: action, v: value }); 

I have user_id and i could add user_id sender

On server:

socket.on('send', function (data) { socket.broadcast.emit('request', { request: data }); }); 

Now the data is sent to all users listening to port, but I would like to only 2 by 2 users can get data.

So, users 1 & 2 are having there "channel", and users 3 & 4 theirs.

1 Answer 1

2

You need the id of the socket (socket.id) you want to send the request. Probably you will need an array with the user_id and its socketID (you can save it when the user enters). Then, when you know the socket id, you can send a message only to this socket.

io.sockets.socket(socketID).emit('request', { request: data }); 
Sign up to request clarification or add additional context in comments.

1 Comment

I wonder that each new sockets use how much resources?.what happen if I use sockets for chatting and I open 1 million socket at same time?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.