Answer the question
In order to leave comments, you need to log in
Why is tsp connecting slowly, where exactly is the limitation?
const net = require('net');
const TCP_CONNECTION_TIMEOUT = 5555;
const checkTcp = (port, ip) => new Promise((resolve) => {
const client = new net.Socket();
client.setTimeout(TCP_CONNECTION_TIMEOUT);
client.connect(port, ip, () => {
resolve(true);
client.destroy();
});
client.on('error', () => {
resolve(false);
client.destroy();
});
});
console.time(1);
await Promise.all(proxies.map(({port, ip})=>checkTcp(port, ip) ))
console.timeEnd(1);
Answer the question
In order to leave comments, you need to log in
setTimeout just doesn't work, it emits an event, and what to do with it you need to think for yourself,
I haven't read the doc https://nodejs.org/api/net.html#net_socket_settime...
socket.setTimeout(3000);
socket.on('timeout', () => {
console.log('socket timeout');
socket.end();
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question