Created
January 10, 2013 09:23
-
-
Save shigeki/4500716 to your computer and use it in GitHub Desktop.
課題2
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 maxreq = 1000; | |
var para = 10; | |
var port = 12345; | |
var counter = 0; | |
var server = net.createServer(function(socket) { | |
if (counter === maxreq) server.close(); | |
}).listen(port, function() { | |
function client_connect() { | |
if (counter++ >= maxreq) return; | |
var client = net.connect({port: port}, function() { | |
client.end(); | |
}); | |
client.on('close', function() { | |
client_connect(); | |
}); | |
} | |
for(var i = 0; i < para; i++) { | |
client_connect(); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment