I am trying to implement client to client messaging in my app, using socket.io
, and node.js
and Android
.
I searched a little, and found a lot of tutorials, explaining how to deal with targetting specific client when sending messages through socket.io
socket.
Send message to specific client with socket.io and node.js
The solution is almost always the same : Creating a hashmap object, linking user info such as its username
, email address
(or anything unique allowing to identify it), with its socketid
.
Then calling io.clients[sessionID].send()
Now I have two questions :
This would work if only one instance of the
app
is running, but imagine if my app is divided in multiple instances (for large app). What if a clientA
, connected to instanceX
, wants to send message to userB
, connected to instanceZ
. If, as seen in the example,socketids
are stored directly in a simple object existing in the script, some sockets wont know about others users existing in an other instance.If I am totally wrong (and I might), is this a good practice to store all user's
socketids
in a single variable ? If yes, would it still be okay with a 50000+ users enviromnment ? If no, should I find another solution like storing user'ssocketids
in database ?