1.nodejs uses the ws library
2. The code for the user to disconnect is written as follows
var WebSocketServer = require("D:/0.ProgramFiles/2.Devel/4.NodeJs/node_modules/ws").Server;
var wss = new WebSocketServer({port: 8888});
var userList = [];
wss.on("connection", function (ws,req) {
// console.log(req.connection.remoteAddress)
console.log(getUUID());
ws.on("message", function (message) {
console.log(":" + message);
wss.clients.forEach(function each(client) {
client.send(message);
});
});
ws.on("close", function (message) {
console.log(id);
});
});
the current situation is:
after the user closes the foreground web page directly, the backend can only receive the number 1001,
how can I get exactly which user has gone offline?