節點中的 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