Skip to content

Instantly share code, notes, and snippets.

@igorzi
Created June 14, 2012 16:50
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save igorzi/2931446 to your computer and use it in GitHub Desktop.
Save igorzi/2931446 to your computer and use it in GitHub Desktop.
var net = require('net');
var serverConnections = 0;
var clientConnections = 0;
// Server: accept connections and set keep-alive
net.createServer(function(socket) {
socket.setKeepAlive(true, 0); // <-----
serverConnections++;
console.log(serverConnections);
}).listen(8080);
// Client: make 1000 connections
(function connect() {
net.connect(8080, function(err){
clientConnections++;
if (err) console.log(err);
if (clientConnections < 1000) {
connect();
}
});
})();
@japlic
Copy link

japlic commented Oct 5, 2022

thx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment