Javascript Node.js TCP/IP服务器队列不工作
我正在编写一个TCP/IP队列,它应该将最大连接用户数限制为3,并让其他任何用户等待,直到用户断开连接。以下是我正在使用的函数:Javascript Node.js TCP/IP服务器队列不工作,javascript,node.js,tcp,queue,Javascript,Node.js,Tcp,Queue,我正在编写一个TCP/IP队列,它应该将最大连接用户数限制为3,并让其他任何用户等待,直到用户断开连接。以下是我正在使用的函数: var maxClients = 3; var currentClients = 0; var _pending = []; function process_pending() { if (_pending.length > 0) { var client = _pending.shift(); currentClients++;
var maxClients = 3;
var currentClients = 0;
var _pending = [];
function process_pending()
{
if (_pending.length > 0) {
var client = _pending.shift();
currentClients++;
client(function()
{
currentClients--;
process.nextTick(process_pending);
});
}
}
function client_limit(client)
{
if (currentClients < maxClients) {
currentClients++;
client(function()
{
currentClients--;
process.nextTick(process_pending);
});
}
else
{
console.log('Overloaded, queuing clients...');
_pending.push(client);
}
}
不能正常工作,我该如何修复它
client(function()
{
currentClients--;
process.nextTick(process_pending);
});