Last active
December 30, 2015 03:49
-
-
Save yorkie/7772026 to your computer and use it in GitHub Desktop.
quick tcp connection
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
exports.port = 10010; | |
var net = require('net'); | |
var tls = require('tls'); | |
var j = 0; | |
var k = 0; | |
function createTCP () { | |
var start = Date.now(); | |
var client = net.connect(993, 'imap.qq.com', function () { | |
k++; | |
console.log('#%d, spent: %d, k: %d', j, Date.now() - start, k); | |
client.destroy(); | |
}); | |
client.on('error', function (e) { | |
//k++; | |
console.log(e); | |
client.destroy(); | |
}) | |
}; | |
setInterval(function () { | |
if (j++>100) { | |
if (k > 1000) { | |
console.log('total: %d, total: %d', process.uptime(), k); | |
process.exit(0); | |
} | |
return; | |
}; | |
createTCP(); | |
createTCP(); | |
createTCP(); | |
createTCP(); | |
createTCP(); | |
createTCP(); | |
createTCP(); | |
createTCP(); | |
createTCP(); | |
createTCP(); | |
createTCP(); | |
createTCP(); | |
}, 100) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var net = require('net'); | |
var tls = require('tls'); | |
var j = 0; | |
function createTCP (callback) { | |
if (j++ > 1000) { | |
console.log(process.uptime()); | |
return process.exit(); | |
} | |
var start = Date.now(); | |
var client = net.connect(993, 'imap.qq.com', function () { | |
console.log('#%d, spent: %d', j, Date.now() - start); | |
callback(createTCP); | |
}) | |
}; | |
for (var i=0; i<10; i++) { | |
createTCP(createTCP); | |
createTCP(createTCP); | |
createTCP(createTCP); | |
createTCP(createTCP); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment