API/socketapi.md
2025-06-02 11:59:26 +08:00

70 lines
906 B
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Socket API 文档
## 1. 连接信息
- 地址: localhost
- 端口: 8888
- 协议: TCP
## 2. 消息格式
所有消息均为JSON格式必须包含type字段
### 2.1 注册请求
```json
{
"type": "register",
"username": "string",
"password": "string"
}
```
### 2.2 登录请求
```json
{
"type": "login",
"username": "string",
"password": "string"
}
```
### 2.3 聊天消息
```json
{
"type": "chat",
"message": "string"
}
```
## 3. 响应格式
### 3.1 注册响应
```json
{
"success": boolean,
"message": "string"
}
```
### 3.2 登录响应
```json
{
"status": "success|error",
"message": "string"
}
```
### 3.3 聊天广播
```json
{
"type": "chat",
"user": "string",
"message": "string"
}
```
## 4. 状态码
- 200: 操作成功
- 403: 用户名已存在(注册时)
- 401: 认证失败(登录时)
- 500: 服务器内部错误