Commit 938ee7fc authored by 邱旭's avatar 邱旭

默认变更列表

parent 833de141
...@@ -47,3 +47,30 @@ server.listen(3001, "0.0.0.0", () => { ...@@ -47,3 +47,30 @@ server.listen(3001, "0.0.0.0", () => {
console.log("服务启动完毕"); console.log("服务启动完毕");
}); });
``` ```
## 在井字棋中连接我们的服务
```javascript
const ws = new WebSocket("ws://0.0.0.0:3001");
ws.onopen = (event) => {
}
ws.onmessage = (event) => {
console.log(event.data);
}
ws.onclose = (event) => {
console.log(event);
}
ws.onerror = (event) => {
console.log(event);
}
```
WebSocket 基本事件:
| 事件名 | 意义 |
| :----: | :----: |
| open | 连接 |
| message | 收到消息 |
| close | 关闭 |
| error | 异常关闭 |
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment