1 Star 0 Fork 4

50/nodejs

forked from 姿势喵/nodejs 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
flash843.js 1.18 KB
一键复制 编辑 原始数据 按行查看 历史
let socketServer = require('./modules/socket_server');
let Log = require('./modules/log');
let str = "<cross-domain-policy><site-control permitted-cross-domain-policies=\"all\"/><allow-access-from domain=\"*\" to-ports=\"*\"/></cross-domain-policy>\0";
let buf = Buffer.alloc(256);
buf.write(str, 0, str.length+4);
let mapSockets = new Map();
let log = new Log();
global.log = log;
function recvCallback(s,data) {
// console.log(data);
if (data=="<policy-file-request/>") {
try {
s.write(buf);
log.print("send <cross-domain-policy>");
} catch (err) {
log.error("socket send error "+err);
}
}
}
function connCallback(s) {
// console.log(data);
mapSockets.set(s, Date.now()+10000);
}
function closeCallback(s,err) {
mapSockets.delete(s);
}
let server = new socketServer(843);
server.startListen(connCallback, null, recvCallback, closeCallback);
setInterval(() => {
let now = Date.now();
log.print("check socket timeout, total:"+mapSockets.size);
mapSockets.forEach(function (value, key, map) {
if (value<now) {
key.end();
log.print("socket timeout!");
}
});
}, 60000);
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/q50/nodejs.git
git@gitee.com:q50/nodejs.git
q50
nodejs
nodejs
master

搜索帮助