Croupier C# SDK
指南
API 参考
GitHub
指南
API 参考
GitHub
  • 开始使用

    • 指南
    • 安装
    • 快速开始
    • 配置
    • 依赖注入
  • 高级用法

    • 异步处理器
    • 错误处理
    • Unity 集成

配置

ClientConfig 选项

ClientConfig 是 SDK 的核心配置类:

public class ClientConfig
{
    public string AgentAddr { get; set; } = "127.0.0.1:19090";
    public string ServiceId { get; set; } = "csharp-service";
    public string ServiceVersion { get; set; } = "1.0.0";
    public string GameId { get; set; } = "default-game";
    public string Env { get; set; } = "dev";
    public string LocalAddr { get; set; } = "0.0.0.0:0";
    public bool Insecure { get; set; }
    public string? CertFile { get; set; }
    public string? KeyFile { get; set; }
    public string? CaFile { get; set; }
    public string? ServerName { get; set; }
    public int TimeoutSeconds { get; set; } = 30;
    public int HeartbeatIntervalSeconds { get; set; } = 30;
    public bool AutoReconnect { get; set; } = true;
    public int ReconnectIntervalSeconds { get; set; } = 5;
    public int MaxConcurrentMessages { get; set; } = 100;
    public int MaxMessageSize { get; set; } = 4 * 1024 * 1024;
}

环境变量

SDK 支持通过环境变量配置:

变量名说明默认值
CROUPIER_AGENT_ADDRAgent 地址127.0.0.1:19090
CROUPIER_SERVICE_ID服务 IDcsharp-service
CROUPIER_SERVICE_VERSION服务版本1.0.0
CROUPIER_GAME_ID游戏 IDdefault-game
CROUPIER_ENV环境dev
CROUPIER_LOCAL_ADDR本地监听地址0.0.0.0:0
CROUPIER_INSECURE跳过 TLSfalse
CROUPIER_CERT_FILE客户端证书-
CROUPIER_KEY_FILE客户端私钥-
CROUPIER_CA_FILECA 证书-
CROUPIER_SERVER_NAMESNI 服务器名-
CROUPIER_TIMEOUT_SECONDS连接超时30
CROUPIER_AUTO_RECONNECT自动重连true
CROUPIER_RECONNECT_INTERVAL_SECONDS重连间隔5

从环境变量加载

using Croupier.Sdk.Configuration;

var configProvider = new EnvironmentConfigProvider();
var config = configProvider.GetConfig();
var client = new CroupierClient(config);

JSON 文件配置

创建 appsettings.json:

{
  "Croupier": {
    "AgentAddr": "127.0.0.1:19090",
    "ServiceId": "my-service",
    "GameId": "my-game",
    "Env": "production",
    "Insecure": false,
    "AutoReconnect": true
  }
}

使用 IOptions<T> 读取:

builder.Services.Configure<ClientConfig>(
    builder.Configuration.GetSection("Croupier"));
在 GitHub 上编辑此页
最后更新: 2026/1/9 14:15
Prev
快速开始
Next
依赖注入