# 4.2.8 命名空间客户端回调 namespace\_clients\_callback

* `callback` (Function)

取连接到此命名空间的客户端ID列表（如果适用，跨所有节点）。

```javascript
const io =require('socket.io')();
io.of('/chat'),clients((error,clients)=>{
    if (error) throw error;
    console.log(clients) // => [PZDoMHjiu8PYfRiKAAAF, Anw2LatarvGVVXEIAAAD]
})
```

获取命名空间房间中所有客户端的示例：

```javascript
io.of('/chat').in('general').clients((error,clients)=>{
    if(error) throw error;
    console.log(clients)// [Anw2LatarvGVVXEIAAAD]
})
```

与广播一样，默认值是来自默认命名空间 `/` 的所有客户端：

```javascript
io.clients((error,clients)=>{
    if(error) throw error;
    console.log(clients); // [6em3d4TJP8Et9EMNAAAA, G5p55dHhGgUnLUctAAAB]
})
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://socket.gitbook.io/docs/4-fu-wu-duan-apiserverapi/4.2-ming-ming-kong-jian-namespace/namespace_clients_callback.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
