Home > other >  Nodejs websocket how to realize the specified ID to send information, including for the man who is n
Nodejs websocket how to realize the specified ID to send information, including for the man who is n

Time:10-24

I learn the socket into the dead end
Problem a:
How to implement websockt specific server specified ID send messages, if I received the client AA to send, including userid, name, the message, I think the userid as a unique identifier ID, could you tell me how to send information to the client BB, I and can't be wrong to client CC
 
WSS) on (' connection ', function (ws) {
Ws. On (' message ', function (the message) {
Var msg_json=JSON. Parse (message);
Var userid=msg_json. Userid;
Var name=msg_json. Name;
Var MSG=msg_json. MSG;
The console. The log (' received: id: % s, % s sent % s', userid, name, MSG);
});
});

A userid="JXS" name="jiangsu province" MSG="in recent days will continue to cool"

For demo code, thank you, rather than empty theory,

Problem two:
I put each user is assigned a unique ID, even if the user "BZX" is not online, database ID, how to send message to users "BZX", strives for the demo code, don't empty theory,

  • Related