一个基于 C++ 的聊天服务器,支持实时消息传递、论坛功能和文件共享。
- 编程语言: C++17
- 数据库: SQLite3
- 网络协议: HTTP/1.1
- 数据格式: JSON
- 构建工具: Make
- 线程库: pthread
- Linux 操作系统
- GCC 7.0+ (支持 C++17)
- SQLite3 开发库
- pthread 库
Ubuntu/Debian:
sudo apt update
sudo apt install build-essential libsqlite3-devArch Linux:
sudo pacman -S base-devel sqlite- 克隆项目
git clone https://github.com/Flourite423/Talkbox-server.git
cd Talkbox-server- 编译项目
make- 启动服务器
# 使用默认端口 8080
./scripts/start.sh
# 或指定端口
./scripts/start.sh 9000- 测试服务器
# 运行测试脚本
./scripts/test.sh详细的 API 接口文档请查看 API.md。
POST /api/register- 用户注册POST /api/login- 用户登录POST /api/logout- 用户登出GET /api/messages- 获取消息列表POST /api/messages- 发送消息GET /api/forums- 获取论坛帖子POST /api/forums- 发布帖子POST /api/upload- 上传文件GET /api/download- 下载文件
# 用户注册
curl -X POST http://localhost:8080/api/register \
-H "Content-Type: application/json" \
-d '{"username": "alice", "password": "123456"}'
# 用户登录
curl -X POST http://localhost:8080/api/login \
-H "Content-Type: application/json" \
-d '{"username": "alice", "password": "123456"}'Talkbox-server/
├── src/ # 源代码目录
│ ├── main.cpp # 程序入口
│ ├── server.cpp/h # 服务器核心
│ ├── database.cpp/h # 数据库操作
│ ├── user_manager.cpp/h # 用户管理
│ ├── message_service.cpp/h # 消息服务
│ ├── forum_service.cpp/h # 论坛服务
│ ├── file_manager.cpp/h # 文件管理
│ └── common.cpp/h # 通用工具
├── build/ # 编译输出目录
├── scripts/ # 脚本目录
│ ├── start.sh # 启动脚本
│ └── test.sh # 测试脚本
├── uploads/ # 文件上传目录
├── Makefile # 构建配置
├── API.md # API 文档
├── README.md # 项目说明
└── LICENSE # 许可证
# 编译项目
make
# 清理构建文件
make clean
# 安装到系统 (需要 root 权限)
sudo make install
# 卸载
sudo make uninstall详细信息请查看 LICENSE 文件。