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

906 B
Raw Permalink Blame History

Socket API 文档

1. 连接信息

  • 地址: localhost
  • 端口: 8888
  • 协议: TCP

2. 消息格式

所有消息均为JSON格式必须包含type字段

2.1 注册请求

{
    "type": "register",
    "username": "string",
    "password": "string"
}

2.2 登录请求

{
    "type": "login",
    "username": "string",
    "password": "string"
}

2.3 聊天消息

{
    "type": "chat",
    "message": "string"
}

3. 响应格式

3.1 注册响应

{
    "success": boolean,
    "message": "string"
}

3.2 登录响应

{
    "status": "success|error",
    "message": "string"
}

3.3 聊天广播

{
    "type": "chat",
    "user": "string",
    "message": "string"
}

4. 状态码

  • 200: 操作成功
  • 403: 用户名已存在(注册时)
  • 401: 认证失败(登录时)
  • 500: 服务器内部错误