Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
agent.maxFreeSockets Property in Node.js
The agent.maxFreeSockets property defines the number of sockets that are left open while in the free state. This is a part of the 'http' module interface.
Syntax
agent.maxFreeSockets : number
Parameters
The above function can accept the following parameters −
number – This defines the number of sockets that can be kept open in the free state. Its default value is set to 256.
Example
Create a file with name – maxFreeSockets.js and copy the below code snippet. After creating file, use the following command to run this code as shown in the example below −
node maxFreeSockets.js
maxFreeSockets.js −
// agent.maxFreeSockets method Demo example
// Importing the http & agentkeepalive module
const http = require('http');
const agent = require('agentkeepalive');
const keepaliveAgent = new agent({
maxSockets: 100,
maxFreeSockets: 10,
timeout: 60000, // active socket keepalive for 60 seconds
freeSocketTimeout: 30000, // free socket keepalive for 30 seconds
});
const options = {
host: 'tutorialspoint.com',
port: 80,
path: '/',
method: 'GET',
agent: keepaliveAgent,
};
console.log("Max free sockets: ",keepaliveAgent.maxFreeSockets);
console.log('[%s] agent status changed: %j', Date(),
keepaliveAgent.getCurrentStatus());
Output
C:\home
ode>> node maxFreeSockets.js Max free sockets: 10 [Fri Apr 30 2021 12:21:12 GMT+0530 (India Standard Time)] agent status changed: {"createSocketCount":0,"createSocketErrorCount":0,"closeSocketCount":0,"errorS ocketCount":0,"timeoutSocketCount":0,"requestCount":0,"freeSockets":{},"socket s":{},"requests":{}}
Advertisements