-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
61 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# 协议相关 | ||
|
||
## 协议的定义 | ||
|
||
协议分为两类:**http协议**和**websocket协议**。 | ||
|
||
所有的请求类都通过**http协议**,心跳和推送类通过**websocket协议**。 | ||
|
||
### http协议 | ||
|
||
http协议全部采用POST请求,请求体和回包都采用json格式。 | ||
|
||
请求: | ||
|
||
| 字段 | 类型 | 备注 | | ||
|------|-----|---------------------------------------| | ||
| name | str | 功能名 | | ||
| data | obj | 协议内容,下文一一列举(如果协议体为空,则没有这个字段,以便减小协议大小) | | ||
|
||
示例: | ||
|
||
```shell | ||
curl http://localhost:8080 \ | ||
-X POST \ | ||
-d '{"name": "login_cs", "data": {"name": "test01"}}' | ||
``` | ||
|
||
返回: | ||
|
||
| 字段 | 类型 | 备注 | | ||
|------|-----|---------------------------------------| | ||
| code | int | 0表示成功 | | ||
| msg | str | 如果code不为0,则为错误信息,否则没有这个字段 | | ||
| data | obj | 协议内容,下文一一列举(如果协议体为空,则没有这个字段,以便减小协议大小) | | ||
|
||
### websocket协议 | ||
|
||
也采用json格式,只有心跳和推送类两种,客户端to服务器和服务器to客户端的协议格式一致: | ||
|
||
| 字段 | 类型 | 备注 | | ||
|------|-----|---------------------------------------| | ||
| name | str | 功能名 | | ||
| data | obj | 协议内容,下文一一列举(如果协议体为空,则没有这个字段,以便减小协议大小) | | ||
|
||
示例: | ||
|
||
```json | ||
{ | ||
"name": "heart_sc", | ||
"data": { | ||
"now": 12345433342 | ||
} | ||
} | ||
``` | ||
|
||
## 全部协议 | ||
|
||
一一列举中。。。 |