我在尝试终止nodejs net中套接字函数内的所有进程时遇到问题:套接字断开连接后循环继续运行。有没有办法杀死套接字调用的所有进程?
net.createServer(function (socket) {
socket.on('end', function () {
//How kill all processes of the current socket ???
});
socket.on('error', function () {
//How kill all processes of the current socket ???
});
i=0;
setInterval(function () {//Waiting other peer for 5sec
i++;
console.log("loop");
if(i>=10){
clearInterval(this);
}
}, 1000);
}).listen(1000);
最佳答案
socket.disconect(0);
应该终止连接。
关于node.js - 如何使用 Nodejs net 正确退出套接字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36104549/