# 1-7 作业(Homework)

> 针对单个用户，主动发消息，怎么做到的？

范例如下：

```javascript
const app = express();

const io = socket(app.listen(444, () => {
    console.info('socket io start:444');
}));
io.on('connection', _websocket);

// 对数组第一个ids广播消息
let chatIds=[]
const chat = io.of('/chat').on('connection',(socket)=>{
    chatIds.push(socket.id)

    let id = chatIds[chatIds.length-1]
    setInterval(()=>{
        console.log(1,id)
        socket.broadcast.to(chatIds[0]).emit('hello', 'axxxx');
  },5000);
});
})
```

## 作业

以下是改进应用程序的想法：

* 当有人连接或者断开连接时，向连接的用户广播消息
* 添加对昵称的支持
* 不要给用户发送相同的消息，而在它按下回车后直接附加消息
* 添加“{用户}”正在输入的功能
* 显示谁在线
* 添加私人消息
* 分享你的改进


---

# 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/1-zhi-nan-guide/homework.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.
