// Check for died connections at regular intervals. setInterval(function () { wsServer.clients.forEach(function (connection) { if (connection.isAlive === false) { console.log("Connection died", connection.id); return connection.terminate(); } // Request the client to respond with pong. Client does this automatically. connection.isAlive = false; connection.ping(function () {}); }); }, 30000);
// 2分钟之后广播给所有的客户端 setTimeout(() => { wss.clients.forEach(client => { client.send(`server broadcast to all client => [${client.id}]: ${new Date()}`) }) }, 2 * 60 * 1000)
if(sessions[msgObj.targetId]){ wss.clients.forEach((client) => { if(client.id === msgObj.targetId){ let data = { time : msgObj.time,
debug('dispatch.do', socket.id, channel, message);
}); console.log("New connection", connection.id); console.log("Connection closed", connection.id, "code", code, "reason", reason); mongoConnection.end(); }); console.log("Connection error", connection.id, "error", error); mongoConnection.write(fragment, function (error) { if (error) { console.log("Mongo connection write error", connection.id, "error", error); console.log("Connection send error", connection.id, "error", error); connection.terminate(); console.log("Mongo connection closed", connection.id); connection.close(); }); console.log("Mongo connection error", connection.id, "error", error); }); console.log("Mongo connection timeout", connection.id); mongoConnection.destroy(); });