# socks 中文文档

规范地址：https://npmcn.com/package/socks/

版本：2\.8\.10
npm 元数据更新时间：2026-09-02T21:42:49.770Z
中文译文更新时间：2026-11-05T16:12:21.799Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/socks
原文对照：https://npmcn.com/package/socks/?lang=original
项目主页：https://github.com/JoshGlazebrook/socks/
源码仓库：https://github.com/JoshGlazebrook/socks

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：156 kB，31 个文件
- 模块格式：CommonJS
- TypeScript 类型：包内自带
- Node.js 要求：\>= 10\.0\.0
- 运行依赖：2 个
- 首次发布：2013-02-15T12:58:54.652Z
- 最新版本发布：2026-09-02T21:42:49.608Z
- 近 30 天下载量：242615002（2026-10-06 至 2026-11-04，npm 官方下载统计）
- 已发布版本数：56（近 12 个月 3 个）

## 中文简介

全功能的 SOCKS 代理客户端支持 SOCKSv4, SOCKSv4a, 和 SOCKSv5. 包括宾德和协理功能.

## 安装

```sh
npm install socks
```

也可以使用：`pnpm add socks`、`yarn add socks`、`bun add socks`

## README

# 袜子 [![Build Status](https://travis-ci.org/JoshGlazebrook/socks.svg?branch=master)](https://travis-ci.org/JoshGlazebrook/socks) [![Coverage Status](https://coveralls.io/repos/github/JoshGlazebrook/socks/badge.svg?branch=master)](https://coveralls.io/github/JoshGlazebrook/socks?branch=v2)

全功能的 SOCKS 代理客户端支持 SOCKSv4, SOCKSv4a, 和 SOCKSv5. 包括宾德和协理功能.

> 找Node.js探员? 检查 [节点- socks- 代用剂](https://github.com/TooTallNate/node-socks-proxy-agent)。 。 。 .

### 特征

-   支持 SOCKS v4, v4a, v5 和 v5h 协议.
-   支持CONNECT,BIND,以及ASOCIATE命令.
-   支持召回,承诺,以及代理连接创建的async流量控制事件.
-   支持代理链(只有CONNECT).
-   支持用户/密码字认证.
-   支持自定义认证 .
-   已建入 UDP 帧创建和剖析函数 .
-   用 TypeScript 创建,提供了类型定义.

### 所需资源

-   节点.js v1.0+ (请使用 [单曲](https://github.com/JoshGlazebrook/socks/tree/82d83923ad960693d8b774cafe17443ded7ed584) 用于旧版本的Node.js)

### 找V1吗?

-   V1 的文档可用 [这里](https://github.com/JoshGlazebrook/socks/tree/82d83923ad960693d8b774cafe17443ded7ed584)

## 安装

`yarn add socks`

或者说

`npm install --save socks`

## 使用量

```typescript
// TypeScript
import { SocksClient, SocksClientOptions, SocksClientChainOptions } from 'socks';

// ES6 JavaScript
import { SocksClient } from 'socks';

// Legacy JavaScript
const SocksClient = require('socks').SocksClient;
```

## 快速启动示例

在80号口连接到github.com(192.30.253.113),使用SOCKS代理.

```javascript
const options = {
  proxy: {
    host: '159.203.75.200', // ipv4 or ipv6 or hostname
    port: 1080,
    type: 5 // Proxy version (4 or 5)
  },

  command: 'connect', // SOCKS command (createConnection factory function only supports the connect command)

  destination: {
    host: '192.30.253.113', // github.com (hostname lookups are supported with SOCKS v4a and 5)
    port: 80
  }
};

// Async/Await
try {
  const info = await SocksClient.createConnection(options);

  console.log(info.socket);
  // <Socket ...>  (this is a raw net.Socket that is established to the destination host through the given proxy server)
} catch (err) {
  // Handle errors
}

// Promises
SocksClient.createConnection(options)
.then(info => {
  console.log(info.socket);
  // <Socket ...>  (this is a raw net.Socket that is established to the destination host through the given proxy server)
})
.catch(err => {
  // Handle errors
});

// Callbacks
SocksClient.createConnection(options, (err, info) => {
  if (!err) {
    console.log(info.socket);
    // <Socket ...>  (this is a raw net.Socket that is established to the destination host through the given proxy server)
  } else {
    // Handle errors
  }
});
```

## 链式代理

**说明:** 链路只在使用SOCKS连接指令时才被支持,而链路只能通过特殊的工厂链路功能来完成.

此示例通过两个 SOCKS 代理到 ip-api.com 实现代理链. 一旦连接到目的地,它就会发出HTTP请求,以获得JSON响应,返回请求的ip信息.

```javascript
const options = {
  destination: {
    host: 'ip-api.com', // host names are supported with SOCKS v4a and SOCKS v5.
    port: 80
  },
  command: 'connect', // Only the connect command is supported when chaining proxies.
  proxies: [ // The chain order is the order in the proxies array, meaning the last proxy will establish a connection to the destination.
    {
      host: '159.203.75.235', // ipv4, ipv6, or hostname
      port: 1081,
      type: 5
    },
    {
      host: '104.131.124.203', // ipv4, ipv6, or hostname
      port: 1081,
      type: 5
    }
  ]
}

// Async/Await
try {
  const info = await SocksClient.createConnectionChain(options);

  console.log(info.socket);
  // <Socket ...>  (this is a raw net.Socket that is established to the destination host through the given proxy servers)

  console.log(info.socket.remoteAddress) // The remote address of the returned socket is the first proxy in the chain.
  // 159.203.75.235

  info.socket.write('GET /json HTTP/1.1\nHost: ip-api.com\n\n');
  info.socket.on('data', (data) => {
    console.log(data.toString()); // ip-api.com sees that the last proxy in the chain (104.131.124.203) is connected to it.
    /*
      HTTP/1.1 200 OK
      Access-Control-Allow-Origin: *
      Content-Type: application/json; charset=utf-8
      Date: Sun, 24 Dec 2017 03:47:51 GMT
      Content-Length: 300

      {
        "as":"AS14061 Digital Ocean, Inc.",
        "city":"Clifton",
        "country":"United States",
        "countryCode":"US",
        "isp":"Digital Ocean",
        "lat":40.8326,
        "lon":-74.1307,
        "org":"Digital Ocean",
        "query":"104.131.124.203",
        "region":"NJ",
        "regionName":"New Jersey",
        "status":"success",
        "timezone":"America/New_York",
        "zip":"07014"
      }
    */
  });
} catch (err) {
  // Handle errors
}

// Promises
SocksClient.createConnectionChain(options)
.then(info => {
  console.log(info.socket);
  // <Socket ...>  (this is a raw net.Socket that is established to the destination host through the given proxy server)

  console.log(info.socket.remoteAddress) // The remote address of the returned socket is the first proxy in the chain.
  // 159.203.75.235

  info.socket.write('GET /json HTTP/1.1\nHost: ip-api.com\n\n');
  info.socket.on('data', (data) => {
    console.log(data.toString()); // ip-api.com sees that the last proxy in the chain (104.131.124.203) is connected to it.
    /*
      HTTP/1.1 200 OK
      Access-Control-Allow-Origin: *
      Content-Type: application/json; charset=utf-8
      Date: Sun, 24 Dec 2017 03:47:51 GMT
      Content-Length: 300

      {
        "as":"AS14061 Digital Ocean, Inc.",
        "city":"Clifton",
        "country":"United States",
        "countryCode":"US",
        "isp":"Digital Ocean",
        "lat":40.8326,
        "lon":-74.1307,
        "org":"Digital Ocean",
        "query":"104.131.124.203",
        "region":"NJ",
        "regionName":"New Jersey",
        "status":"success",
        "timezone":"America/New_York",
        "zip":"07014"
      }
    */
  });
})
.catch(err => {
  // Handle errors
});

// Callbacks
SocksClient.createConnectionChain(options, (err, info) => {
  if (!err) {
    console.log(info.socket);
    // <Socket ...>  (this is a raw net.Socket that is established to the destination host through the given proxy server)

    console.log(info.socket.remoteAddress) // The remote address of the returned socket is the first proxy in the chain.
  // 159.203.75.235

  info.socket.write('GET /json HTTP/1.1\nHost: ip-api.com\n\n');
  info.socket.on('data', (data) => {
    console.log(data.toString()); // ip-api.com sees that the last proxy in the chain (104.131.124.203) is connected to it.
    /*
      HTTP/1.1 200 OK
      Access-Control-Allow-Origin: *
      Content-Type: application/json; charset=utf-8
      Date: Sun, 24 Dec 2017 03:47:51 GMT
      Content-Length: 300

      {
        "as":"AS14061 Digital Ocean, Inc.",
        "city":"Clifton",
        "country":"United States",
        "countryCode":"US",
        "isp":"Digital Ocean",
        "lat":40.8326,
        "lon":-74.1307,
        "org":"Digital Ocean",
        "query":"104.131.124.203",
        "region":"NJ",
        "regionName":"New Jersey",
        "status":"success",
        "timezone":"America/New_York",
        "zip":"07014"
      }
    */
  });
  } else {
    // Handle errors
  }
});
```

## 宾德示例( TCP 中继)

当绑定命令被发送到 SOCKS v4/v5 代理服务器时,代理服务器开始在一个新的TCP端口上收听,代理转发然后远程主机信息返回客户端. 当另一个远程客户端连接到这个端口的代理服务器时,SOCKS代理发送一个通知,一个接入的连接已被接受到初始客户端,现在一个完整的双复流被建立到初始客户端和连接到该特殊端口的客户端.

```javascript
const options = {
  proxy: {
    host: '159.203.75.235', // ipv4, ipv6, or hostname
    port: 1081,
    type: 5
  },

  command: 'bind',

  // When using BIND, the destination should be the remote client that is expected to connect to the SOCKS proxy. Using 0.0.0.0 makes the Proxy accept any incoming connection on that port.
  destination: {
    host: '0.0.0.0',
    port: 0
  }
};

// Creates a new SocksClient instance.
const client = new SocksClient(options);

// When the SOCKS proxy has bound a new port and started listening, this event is fired.
client.on('bound', info => {
  console.log(info.remoteHost);
  /*
  {
    host: "159.203.75.235",
    port: 57362
  }
  */
});

// When a client connects to the newly bound port on the SOCKS proxy, this event is fired.
client.on('established', info => {
  // info.remoteHost is the remote address of the client that connected to the SOCKS proxy.
  console.log(info.remoteHost);
  /*
    host: 67.171.34.23,
    port: 49823
  */

  console.log(info.socket);
  // <Socket ...>  (This is a raw net.Socket that is a connection between the initial client and the remote client that connected to the proxy)

  // Handle received data...
  info.socket.on('data', data => {
    console.log('recv', data);
  });
});

// An error occurred trying to establish this SOCKS connection.
client.on('error', err => {
  console.error(err);
});

// Start connection to proxy
client.connect();
```

## 协理实例( UDP 中继)

当协理命令被发送到 SOCKS v5 代理服务器时,它会设置一个UDP中继器,允许客户端通过代理服务器向远程主机发送UDP包,同时通过代理服务器接收UDP包回复.

```javascript
const options = {
  proxy: {
    host: '159.203.75.235', // ipv4, ipv6, or hostname
    port: 1081,
    type: 5
  },

  command: 'associate',

  // When using associate, the destination should be the remote client that is expected to send UDP packets to the proxy server to be forwarded. This should be your local ip, or optionally the wildcard address (0.0.0.0)  UDP Client <-> Proxy <-> UDP Client
  destination: {
    host: '0.0.0.0',
    port: 0
  }
};

// Create a local UDP socket for sending packets to the proxy.
const udpSocket = dgram.createSocket('udp4');
udpSocket.bind();

// Listen for incoming UDP packets from the proxy server.
udpSocket.on('message', (message, rinfo) => {
  console.log(SocksClient.parseUDPFrame(message));
  /*
  { frameNumber: 0,
    remoteHost: { host: '165.227.108.231', port: 4444 }, // The remote host that replied with a UDP packet
    data: <Buffer 74 65 73 74 0a> // The data
  }
  */
});

let client = new SocksClient(options);

// When the UDP relay is established, this event is fired and includes the UDP relay port to send data to on the proxy server.
client.on('established', info => {
  console.log(info.remoteHost);
  /*
    {
      host: '159.203.75.235',
      port: 44711
    }
  */

  // Send 'hello' to 165.227.108.231:4444
  const packet = SocksClient.createUDPFrame({
    remoteHost: { host: '165.227.108.231', port: 4444 },
    data: Buffer.from('hello')
  });
  udpSocket.send(packet, info.remoteHost.port, info.remoteHost.host);
});

// Start connection
client.connect();
```

**说明:** 代理机的关联TCP连接必须保持开放,以便UDP继电器工作.

## 其他实例

[文档](https://npmcn.com/package/socks/docs/index.md)

## 从v1 移动

寻找从v1迁移的向导? 听着 [这里](https://npmcn.com/package/socks/docs/migratingFromV1.md)

## Api 参考 :

**说明:** 袜子包括了完整的TypeScript定义. 这些甚至可以不用TypeScript使用,因为大多数IDE(如VS代码)甚至会在JavaScript文件中使用这些类型定义文件来自动完成intellisense.

-   类:袜子密度
    -   [新 SocksClient( 选项\[, 回调\])](https://npmcn.com/package/socks/#readme-new-socksclientoptions)
    -   [类方法: SocksClient.createConnection(选项\[,回调\])](https://npmcn.com/package/socks/#readme-class-method-socksclientcreateconnectionoptions-callback)
    -   [类方法: SocksClient.create ConnectionCham(选项\[,回调\])](https://npmcn.com/package/socks/#readme-class-method-socksclientcreateconnectionchainoptions-callback)
    -   [类方法: SocksClient.createUDPFrame(选项)](https://npmcn.com/package/socks/#readme-class-method-socksclientcreateudpframedetails)
    -   [类方法: SocksClient.parseUD PFrame(数据)](https://npmcn.com/package/socks/#readme-class-method-socksclientparseudpframedata)
    -   [事件: '错误'](https://npmcn.com/package/socks/#readme-event-error)
    -   [事件 : “ 开始 ”](https://npmcn.com/package/socks/#readme-event-bound)
    -   [活动:“建立”](https://npmcn.com/package/socks/#readme-event-established)
    -   [客户端. connect ()](https://npmcn.com/package/socks/#readme-clientconnect)
    -   [客户端.socks 客户端选项](https://npmcn.com/package/socks/#readme-clientconnect)

### 袜子密度

SocksClient 建立 SOCKS 远程目标主机代理连接. 这些代理连接对服务器是完全透明的,一旦建立,就起到完全双相流的作用. 支持SOCKS v4,v4a,v5和v5h,以及连接,绑定和关联命令.

SocksClient支持使用回调,承诺来创建连接,以及使用两个静态工厂函数来创建Aync/await流量控制来创建Connection并创建ConnectionChain. 它还在内部扩展EventEmitter,从而允许基于Aync流量控制的事件处理.

**SOCKS 相容性表格**

注:使用4a时,请具体说明类型:4;使用5h时,请具体说明类型:5.

| 袜子版本 | TCP 常规程序 | UDP 服务器 | IPv4 请检查url=值 (帮助) | IPv6 请检查url=值 (帮助) | 主机名 |
| --- | :-: | :-: | :-: | :-: | :-: |
| SOCKS v4 (英语) | ✅ | ❌ | ✅ | ❌ | ❌ |
| SOCKS v4a (英语) | ✅ | ❌ | ✅ | ❌ | ✅ |
| SOCKS v5( 包括 v5h) | ✅ | ✅ | ✅ | ✅ | ✅ |

### 新建 Socks 客户端( 选项)

-   `options` {袜子Client options} - 一个描述要使用的 SOCKS 代理对象,要发送和建立的命令,以及要连接的目的地主机.

### 袜子浓度选项

```typescript
{
  proxy: {
    host: '159.203.75.200', // ipv4, ipv6, or hostname
    port: 1080,
    type: 5, // Proxy version (4 or 5). For v4a use 4, for v5h use 5.

    // Optional fields
    userId: 'some username', // Used for SOCKS4 userId auth, and SOCKS5 user/pass auth in conjunction with password.
    password: 'some password', // Used in conjunction with userId for user/pass auth for SOCKS5 proxies.
    custom_auth_method: 0x80,  // If using a custom auth method, specify the type here. If this is set, ALL other custom_auth_*** options must be set as well.
    custom_auth_request_handler: async () =>. {
      // This will be called when it's time to send the custom auth handshake. You must return a Buffer containing the data to send as your authentication.
      return Buffer.from([0x01,0x02,0x03]);
    },
    // This is the expected size (bytes) of the custom auth response from the proxy server.
    custom_auth_response_size: 2,
    // This is called when the auth response is received. The received packet is passed in as a Buffer, and you must return a boolean indicating the response from the server said your custom auth was successful or failed.
    custom_auth_response_handler: async (data) => {
      return data[1] === 0x00;
    }
  },

  command: 'connect', // connect, bind, associate

  destination: {
    host: '192.30.253.113', // ipv4, ipv6, hostname. Hostnames work with v4a and v5.
    port: 80
  },

  // Optional fields
  timeout: 30000, // How long to wait to establish a proxy connection. (defaults to 30 seconds)

  set_tcp_nodelay: true // If true, will turn on the underlying sockets TCP_NODELAY option.
}
```

### 类方法: SocksClient.createConnection(选项\[,回调\])

-   `options` {袜子选集} - 一个描述要使用的 SOCKS 代理对象,要发送和建立的命令,以及要连接的目的地主机.
-   `callback` {函数} - 代理连接建立时调用的可选回调函数, 或发生错误 .
-   `returns` {保证} - 返回一个在代理连接建立时解决的保证, 或者在错误发生时被拒绝 .

通过给定的代理给定的目的地主机创建新的代理连接 。 这种工厂功能支持回调和对合成流控制的承诺.

**说明:** 如果提供了回调函数,无论发生出错,承诺都会永远解决. 请在使用此工厂功能时, 请完全使用承诺或回调 .

```typescript
const options = {
  proxy: {
    host: '159.203.75.200', // ipv4, ipv6, or hostname
    port: 1080,
    type: 5 // Proxy version (4 or 5)
  },

  command: 'connect', // connect, bind, associate

  destination: {
    host: '192.30.253.113', // ipv4, ipv6, or hostname
    port: 80
  }
}

// Await/Async (uses a Promise)
try {
  const info = await SocksClient.createConnection(options);
  console.log(info);
  /*
  {
    socket: <Socket ...>,  // Raw net.Socket
  }
  */
  / <Socket ...>  (this is a raw net.Socket that is established to the destination host through the given proxy server)

} catch (err) {
  // Handle error...
}

// Promise
SocksClient.createConnection(options)
.then(info => {
  console.log(info);
  /*
  {
    socket: <Socket ...>,  // Raw net.Socket
  }
  */
})
.catch(err => {
  // Handle error...
});

// Callback
SocksClient.createConnection(options, (err, info) => {
  if (!err) {
    console.log(info);
  /*
  {
    socket: <Socket ...>,  // Raw net.Socket
  }
  */
  } else {
    // Handle error...
  }
});
```

### 类方法: SocksClient.create ConnectionCham(选项\[,回调\])

-   `options` {\\fn黑体\\fs22\\bord1\\shad0\\3aHBE\\4aH00\\fscx67\\fscy66\\2cHFFFFFF\\3cH808080}你觉得呢? 描述要使用的 SOCKS 代理列表、 要发送和建立的命令以及要连接的目的地主机的对象 .
-   `callback` {函数} - 代理连接链建立时调用的可选回调函数, 或发生错误 .
-   `returns` {承诺} - 返回一个在代理连接链建立时解决的保证, 或者在错误发生时被拒绝 .

通过至少包含两个 SOCKS 代理给定目的地主机的列表创建新的代理连接链 。 这种工厂方法支持回调和保证,用于对同源流的控制.

**说明:** 如果提供了回调函数,无论发生出错,承诺都会永远解决. 请在使用此工厂功能时, 请完全使用承诺或回调 .

**说明:** 必须至少提供两个代理才能建立链条.

```typescript
const options = {
  proxies: [ // The chain order is the order in the proxies array, meaning the last proxy will establish a connection to the destination.
    {
      host: '159.203.75.235', // ipv4, ipv6, or hostname
      port: 1081,
      type: 5
    },
    {
      host: '104.131.124.203', // ipv4, ipv6, or hostname
      port: 1081,
      type: 5
    }
  ]

  command: 'connect', // Only connect is supported in chaining mode.

  destination: {
    host: '192.30.253.113', // ipv4, ipv6, hostname
    port: 80
  }
}
```

### 类方法: SocksClient.createUDPFrame(细节)

-   `details` {\\fn黑体\\fs22\\bord1\\shad0\\3aHBE\\4aH00\\fscx67\\fscy66\\2cHFFFFFF\\3cH808080}你觉得呢? 包含远程主机、帧数和帧数据的对象,用于创建 SOCKS UDP 帧包 .
-   `returns` {缓冲} - 包含所有 UDP 帧数据的缓冲 .

创建 SOCKS UDP 帧中继包,该包在使用关联命令进行 UDP 包转发时通过 SOCKS 代理发送和接收 .

**袜子UDPFrame 细节**

```typescript
{
  frameNumber: 0, // The frame number (used for breaking up larger packets)

  remoteHost: { // The remote host to have the proxy send data to, or the remote host that send this data.
    host: '1.2.3.4',
    port: 1234
  },

  data: <Buffer 01 02 03 04...> // A Buffer instance of data to include in the packet (actual data sent to the remote host)
}
interface SocksUDPFrameDetails {
  // The frame number of the packet.
  frameNumber?: number;

  // The remote host.
  remoteHost: SocksRemoteHost;

  // The packet data.
  data: Buffer;
}
```

### 类方法: SocksClient.parseUD PFrame(数据)

-   `data` {缓冲} - 一个包含 SOCKS UDP 帧数据的缓冲实例来解析 .
-   `returns` {\\fn黑体\\fs22\\bord1\\shad0\\3aHBE\\4aH00\\fscx67\\fscy66\\2cHFFFFFF\\3cH808080}你觉得呢? 包含 SOCKS UDP 帧的远程主机,帧数和帧数据的对象.

```typescript
const frame = SocksClient.parseUDPFrame(data);
console.log(frame);
/*
{
  frameNumber: 0,
  remoteHost: {
    host: '1.2.3.4',
    port: 1234
  },
  data: <Buffer 01 02 03 04 ...>
}
*/
```

解析缓冲实例并返回已解析的 SocksUDPFrameDetails 对象.

## 事件: '错误'

-   `err` { SocksClientError} - 一个包含错误消息和原始 SocksClient 选项的错误对象 .

如果试图建立代理连接时发生错误, 此事件会被释放 .

## 事件 : “ 开始 ”

-   `info` \[袜子快活\] 含有Socket和SocksRemoteHost信息的一个天体.

此事件在远程 SOCKS 代理服务器上使用 BIND 命令时被发布 。 此事件显示代理服务器正在监听指定端口的连接 .

**袜子串联事件**

```typescript
{
  socket: net.Socket, // The underlying raw Socket
  remoteHost: {
    host: '1.2.3.4', // The remote host that is listening (usually the proxy itself)
    port: 4444 // The remote port the proxy is listening on for incoming connections (when using BIND).
  }
}
```

## 活动:“建立”

-   `info` \[袜子ClientEstabild Event\] (英语). 含有Socket和SocksRemoteHost信息的一个天体.

此事件在满足以下条件时释放:

1.  在使用 CONNECT 命令时, 和远程主机建立了代理连接 .
2.  当使用 BIND 命令时,一个接入的连接已被代理接受并建立了TCP中继器.
3.  在使用ASOCIATE指令时,已经建立了UDP中继器.

当使用 BIND 时, “ 绑定 ” 将首先被释放, 以表示 SOCKS 服务器正在等待连接, 并提供 SOCKS 服务器正在监听的远程端口 .

使用 ASOCIATE 时, SOCKS 服务器正在接受 UDP 框架包的远程 UDP 端口会发出“ 建立” .

**袜子智能化活动**

```typescript
{
  socket: net.Socket, // The underlying raw Socket
  remoteHost: {
    host: '1.2.3.4', // The remote host that is listening (usually the proxy itself)
    port: 52738 // The remote port the proxy is listening on for incoming connections (when using BIND).
  }
}
```

## 客户端. connect ()

开始连接远程 SOCKS 代理服务器,以建立与目的地主机的代理连接.

## 客户端.socks 客户端选项

-   `returns` {袜子选取} 被传给SocksClient的选项.

获得创建时传递给 SocksClient 的选项 .

**袜子关闭错误**

```typescript
{ // Subclassed from Error.
  message: 'An error has occurred',
  options: {
    // SocksClientOptions
  }
}
```

# 进一步阅读:

请阅读SOCKS 5规格,了解如何使用BIND和Associate的更多信息. [http://www.ietf.org/rfc/rfc1928.txt (中文(简体) )](http://www.ietf.org/rfc/rfc1928.txt)

# 许可证

这项工作根据以下条例获得许可: [麻省理工学院许可证](http://en.wikipedia.org/wiki/MIT_License)。 。 。 .

## 常见问题

### socks 是什么？

全功能的 SOCKS 代理客户端支持 SOCKSv4, SOCKSv4a, 和 SOCKSv5\. 包括宾德和协理功能\.

### 如何安装 socks？

在项目目录运行 npm install socks，或使用 pnpm add / yarn add / bun add。

### socks 支持 TypeScript 吗？

支持。包内自带 TypeScript 类型声明（package\.json 声明了 types 入口），安装后即可获得类型提示，无需再安装 @types 包。

### socks 支持 ESM 还是 CommonJS？

以 CommonJS 形式发布，可以直接 require\(\)；在 ES Module 项目中也可以用 import 引入（Node\.js 会把 module\.exports 作为默认导出）。

### socks 需要什么版本的 Node\.js？

package\.json 的 engines 字段要求 Node\.js \>= 10\.0\.0。版本不符时 npm 默认只给出警告，开启 engine-strict 后会拒绝安装。

### socks 可以商用吗？

socks 使用 MIT 许可。宽松许可：允许商业使用、修改和再分发，通常只需在分发时保留原版权与许可声明。以上为概括，不构成法律意见，请以许可原文为准。

### socks 的下载量有多少？

根据 npm 官方下载统计，socks 在 2026/10/06 – 2026/11/04 这 30 天内被下载 242,615,002 次，日均约 8,087,167 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入，适合横向比较热度，不能直接等同于使用人数。

### socks 还在维护吗？

最新版本 2\.8\.10 发布于 2026/09/03（2 个月前）；至今共发布 56 个版本，其中过去 12 个月发布了 3 个；首次发布于 2013/02/15。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

