# wsscoket 对接说明
## 客户端对接测试页面
[{{服务端地址}}/ws/client](http://127.0.0.1:8088/ws/client)

## 客户端对接websocket流程
### websocket的连接
1. 客户端登录后获取uuid
2. 连接服务端websocket后,在10s内发送一下格式的数据,否则websocket连接将断开。
uuid请添加登录后获取的,如果uuid不正确,连接也会断开
```json
{
  "type": "register",
  "from": "",
  "to": "0",
  "content": {
    "uuid":"用户的uuid"
  }
}
```
注册成功后,服务端将返回客户端临时id
```json
{"clientId":"02de5759-3f0a-47fa-a79f-afe61c39c5aa"}
```

### weboscket 数据发送测试
消息类型`type="test"`时,客户端将会把`content`内容原路返回,以此来测试最基本的通讯功能。
```json
{
  "type": "test",
  "from": "用户clientId",
  "to": "0",
  "content": {
    "demo":"testdemo"
  }
}
```

### websocket消息类型说明
#### 错误消息 
在websocket通讯过程中,服务端会对客户端发送过来的消息进行验证。

| type字段 | content字段            | 说明                           |
|--------|----------------------|------------------------------|
| Error  | Permission denied    | 拒绝访问。 此报错一般出现在首次连接,验证uuid的时候 |
| Error  | Invalid data format  | 无效的数据格式。消息内容未按照指定格式书写        |
| Error  | Unknown message type | 未知的消息类型。接收到了未定义的type         |

**错误消息示例:**
```json
{"type":"Error","content":"Permission denied","from":"0","to":"tempId"}
//{"type":"Error","content":"Invalid data format","from":"0","to":""}
//{"type":"Error","content":"Unknown notice type","from":"0","to":"0"}
```