# 2.1.10 广播消息

* 广播时不支持回调

要进行广播，只需添加广播标志即可发出和发送方法调用。 广播意味着向除了启动它的socket之外的所有人发送消息。

## Server

```javascript
const io = require('socket.io')(80)
io.on('connection',(socket)=>{
    socket.broadcast.emit('user connected')
    socket.broadcast.to('socketId').emit('hi',"hi") //给指定人发送
})
```


---

# 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/2-wen-dang-docs/2.1-gai-lan/broadcasting_messages.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.
