| | |
| | | namespace WIDESEAWCS_Tasks.SocketServer |
| | | { |
| | | /// <summary> |
| | | /// Socket服务端配置 |
| | | /// Socket 服务器配置选项 |
| | | /// </summary> |
| | | /// <remarks> |
| | | /// 用于配置 TCP Socket 服务器的运行参数。 |
| | | /// 配置通过 appsettings.json 的 SocketServer 节点加载。 |
| | | /// </remarks> |
| | | public class SocketServerOptions : IConfigurableOptions |
| | | { |
| | | /// <summary> |
| | | /// 是否启用 |
| | | /// 是否启用 Socket 服务器 |
| | | /// </summary> |
| | | /// <remarks> |
| | | /// 设置为 false 时,服务器不会启动。 |
| | | /// </remarks> |
| | | public bool Enabled { get; set; } = true; |
| | | |
| | | /// <summary> |
| | | /// 监听端口 |
| | | /// 服务器监听端口 |
| | | /// </summary> |
| | | /// <remarks> |
| | | /// TCP 客户端连接到此端口。 |
| | | /// 默认为 2000。 |
| | | /// </remarks> |
| | | public int Port { get; set; } = 2000; |
| | | |
| | | /// <summary> |
| | | /// 监听地址 |
| | | /// 监听地址 |
| | | /// </summary> |
| | | /// <remarks> |
| | | /// 服务器绑定到此地址。 |
| | | /// 0.0.0.0 表示监听所有网络接口。 |
| | | /// </remarks> |
| | | public string IpAddress { get; set; } = "0.0.0.0"; |
| | | |
| | | /// <summary> |
| | | /// 连接队列长度 |
| | | /// 连接队列长度 |
| | | /// </summary> |
| | | public int Backlog { get; set; } = 100; |
| | | /// <remarks> |
| | | /// 等待接受的连接队列最大长度。 |
| | | /// </remarks> |
| | | public int Backlog { get; set; } = 1000; |
| | | |
| | | /// <summary> |
| | | /// 文本编码名称(例如: utf-8, gbk) |
| | | /// 字符编码名称 |
| | | /// </summary> |
| | | /// <remarks> |
| | | /// 用于消息的字符编码,如 utf-8、gbk。 |
| | | /// </remarks> |
| | | public string EncodingName { get; set; } = "utf-8"; |
| | | |
| | | /// <summary> |
| | | /// 是否自动检测编码(尝试 UTF-8 后回退到 GBK) |
| | | /// 是否自动检测编码(针对 GBK 客户端) |
| | | /// </summary> |
| | | /// <remarks> |
| | | /// 当设置为 true 时,会自动检测客户端消息的编码。 |
| | | /// 如果消息是 UTF-8 格式则用 UTF-8 解码,否则尝试 GBK 解码。 |
| | | /// </remarks> |
| | | public bool AutoDetectEncoding { get; set; } = true; |
| | | |
| | | /// <summary> |
| | | /// 客户端空闲超时时间(秒),超过则断开 |
| | | /// 客户端空闲超时时间(秒) |
| | | /// </summary> |
| | | /// <remarks> |
| | | /// 如果客户端在此时间内没有活动,断开连接。 |
| | | /// 设置为 0 表示不启用超时。 |
| | | /// </remarks> |
| | | public int IdleTimeoutSeconds { get; set; } = 300; |
| | | |
| | | /// <summary> |
| | | /// 是否启用心跳检查 |
| | | /// 是否启用心跳检测 |
| | | /// </summary> |
| | | /// <remarks> |
| | | /// 启用后,会在连接空闲时发送心跳探测。 |
| | | /// </remarks> |
| | | public bool EnableHeartbeat { get; set; } = true; |
| | | |
| | | /// <summary> |
| | | /// 日志文件路径(相对于程序运行目录) |
| | | /// 日志文件路径 |
| | | /// </summary> |
| | | /// <remarks> |
| | | /// 日志文件的相对路径,相对于应用程序目录。 |
| | | /// </remarks> |
| | | public string LogFilePath { get; set; } = "socketserver.log"; |
| | | |
| | | /// <summary> |
| | | /// 消息头标识 |
| | | /// </summary> |
| | | /// <remarks> |
| | | /// 用于帧解析的消息头。 |
| | | /// 接收消息时查找此头标识。 |
| | | /// </remarks> |
| | | public string MessageHeader { get; set; } = "<START>"; |
| | | |
| | | /// <summary> |
| | | /// 消息尾标识 |
| | | /// </summary> |
| | | /// <remarks> |
| | | /// 用于帧解析的消息尾。 |
| | | /// 接收消息时查找此尾标识。 |
| | | /// </remarks> |
| | | public string MessageFooter { get; set; } = "<END>"; |
| | | } |
| | | } |