节点中的 agent.maxSockets 属性
agent.maxSockets 属性定义了代理为每个源同时打开的套接字数。默认情况下,此值设为 Infinity。这也是“http”模块的一部分。
语法
agent.maxSockets: number
参数
上述函数可以接受以下参数 -
数 – 定义代理可以拥有的并发套接字数。其默认值设为 Infinity。
示例
使用名称 – maxSockets.js 创建一个文件,并复制以下代码段。在创建文件后,使用如下面的示例所示的命令运行此代码
node maxSockets.js
maxSockets.js
// agent.maxSockets 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.maxSockets);
console.log('[%s] agent status changed: %j', Date(),
keepaliveAgent.getCurrentStatus());输出
C:\home
ode>> node maxSockets.js Max sockets: 100 [Fri Apr 30 2021 12:28:24 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":{}}
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP