update cn doc (#976)

update cn doc for pr #968

Co-authored-by: redsun <jinxueli@imooc.com>
This commit is contained in:
JIN 2024-05-06 04:49:02 +08:00 committed by GitHub
parent 902c973c38
commit 3a22dabef4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 7 additions and 1 deletions

View File

@ -1,6 +1,6 @@
# WebSockets
[WebSockets](https://zh.wikipedia.org/wiki/WebSocket) 允许客户端和服务器之间进行双向通信。与 HTTP 的请求和响应模式不同WebSocket 可以在两端之间发送任意数量的消息。Vapor的WebSocket API允许你创建异步处理消息的客户端和服务器。
[WebSockets](https://zh.wikipedia.org/wiki/WebSocket) 允许客户端和服务器之间进行双向通信。与 HTTP 的请求和响应模式不同WebSocket 可以在两端之间发送任意数量的消息。Vapor WebSocket API 允许你创建异步处理消息的客户端和服务器。
## 服务器
@ -58,6 +58,12 @@ promise.futureResult.whenComplete { result in
}
```
如果使用 `async`/`await`,你可以使用 `await` 来等待异步操作完成。
```swift
try await ws.send(...)
```
### 接收
接收的消息通过 `onText``onBinary` 回调进行处理。