Answer the question
In order to leave comments, you need to log in
Why is the sent message from the server not visible in the message event?
wss.on('connection', function(ws,req) {
const user=getUser(req.url);
ws.onclient=user['viewer_id'];
wss.clients.forEach(function each(client) {
if (client.readyState === WebSocket.OPEN ){
client.send(JSON.stringify({doubleClient:user['viewer_id']}));
}
});
if(MD5(user['api_id']+"_"+user['viewer_id']+"_"+appkey)!==user['auth_key'] || !user['auth_key']){
console.info('Conn End')
ws.close()
}else{
console.info("OK")
}
ws.on('close', function (data) {
console.info('exit')
});
ws.on('message', function (data) {
console.info(data)
try{
const userSend=JSON.parse(data);
if(userSend===data.doubleClient){
console.info('double')
}
console.info(userSend)
}catch (e) {
console.info('Не JSON')
return false
}
})
});
Answer the question
In order to leave comments, you need to log in
Your question is much easier to search on Google: websocket single session management
Here is the actual article in which the author solves a similar problem for his project
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question