README
Socket Handler
This module offers a simple handler which can be used to reduce the number of sockets created. It can be useful in scenarios where a large number of micro transactions are performed or when multiplexed sockets are needed.
The handler will return the same socket, if available, at each request for the same host.
Notice that some benefits are achieved by means of this handler:
- performance: requiring an available socket, when it yet exists, is faster than creating a new one
- fin-less: pending sockets, the ones that hang while waiting for the fin packet, are automatically destroyed
Please, notice also that a socket will not be destroyed until there will be data that need to be consumed.
The handler can be simply used as follows:
var handler = require('sockethandler')();
handler('localhost', function(err, socket) {
// use the socket here
});
handler('localhost', function(err, socket) {
// use the same socket here
});
handler('127.0.0.1', function(err, socket) {
// use another socket here
});