使用示例
本章节提供 Croupier C++ SDK 的各种使用示例。
示例列表
运行示例
构建示例
# 克隆仓库
git clone https://github.com/cuihairu/croupier-sdk-cpp.git
cd croupier-sdk-cpp
# 构建(包含示例)
./scripts/build.sh --examples ON
# 或者使用 CMake
cmake -B build -DBUILD_EXAMPLES=ON
cmake --build build
运行示例
# 确保 Agent 已启动
./build/bin/croupier-example
./build/bin/croupier-virtual-object-demo
./build/bin/croupier-plugin-demo
./build/bin/croupier-comprehensive-demo
前置准备
在运行示例前,需要:
- 启动 Croupier Server
cd /path/to/croupier/server
go run ./services/server -f services/server/etc/server.yaml
- 启动 Croupier Agent
cd /path/to/croupier/server
go run ./services/agent -f services/agent/etc/agent.yaml
- 验证连接
# Agent 默认监听 127.0.0.1:19090
curl http://127.0.0.1:19090/health
示例配置
所有示例使用以下默认配置:
{
"game_id": "demo-game",
"env": "development",
"service_id": "demo-service",
"agent_addr": "127.0.0.1:19090",
"insecure": true
}
可以通过环境变量覆盖:
export CROUPIER_GAME_ID=my-game
export CROUPIER_ENV=production
export CROUPIER_AGENT_ADDR=10.0.0.5:19090
./build/bin/croupier-example
下一步
查看具体示例了解详细用法:
