一款简单易用的基础网络通讯组件库。

ReconnectionOptionTClient

重连插件配置选项

Definition

命名空间: TouchSocket.Sockets
程序集: TouchSocket (在 TouchSocket.dll 中) 版本:4.1.4.7+7f7e1f78093c99347956e09330d5d7aca1d2bdf2
C#
public class ReconnectionOption<TClient>
where TClient : IConnectableClient, IOnlineClient, IDependencyClient
Inheritance
Object    ReconnectionOptionTClient

类型参数

TClient
客户端类型

构造函数

ReconnectionOptionTClient 重连插件配置选项

属性

BackoffMultiplier 退避倍数(用于指数和线性退避)
BaseInterval 基础重连间隔
CheckAction 检查客户端活性的委托。
ConnectAction 尝试连接的委托
ConnectTimeout 在执行连接时,连接时间
LogReconnection 是否记录重连日志
MaxInterval 最大重连间隔
MaxRetryCount 最大重连次数,-1表示无限重连
OnFailed 重连失败回调

当单次重连尝试失败时触发此回调,每次重连失败都会调用

触发时机:在ConnectAsync抛出异常时立即触发

第1参数:重连失败的客户端实例

第2参数:当前重连尝试次数(从1开始计数)

第3参数:导致重连失败的异常信息

OnGiveUp 重连放弃回调

当达到最大重连次数限制,决定放弃继续重连时触发此回调

触发时机:当MaxRetryCount大于0且重连尝试次数达到该限制时

注意:如果MaxRetryCount设置为-1(无限重连),此回调永远不会被触发

第1参数:放弃重连的客户端实例

第2参数:总共尝试的重连次数

OnSuccessed 重连成功回调

当重连操作成功完成时触发此回调

触发时机:

1. 检测到客户端已经在线时

2. 执行ConnectAsync成功后

第1参数:重连成功的客户端实例

PollingInterval 轮询时间间隔
Strategy 重连策略

方法

EqualsDetermines whether the specified object is equal to the current object.
(继承自 Object。)
FinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(继承自 Object。)
GetHashCodeServes as the default hash function.
(继承自 Object。)
GetTypeGets the Type of the current instance.
(继承自 Object。)
MemberwiseCloneCreates a shallow copy of the current Object.
(继承自 Object。)
ToStringReturns a string that represents the current object.
(继承自 Object。)
UseCustom 使用自定义连接策略
UseExponentialBackoff 使用指数退避重连策略 - 每次失败后延迟时间指数增长
UseLinearBackoff 使用线性退避重连策略 - 每次失败后延迟时间线性增长
UseSimple 使用简单重连策略 - 固定间隔重连

扩展方法

ToJsonString 转换为Json
(由 SerializeConvert 定义。)
UseDmtpCheckActionTClient 配置DMTP检活策略

此方法为DMTP客户端配置智能的连接检查策略,支持三级检查:

1. 在线状态检查 - 快速判断连接是否断开

2. 活动时间检查 - 避免频繁检查,优化性能

3. Ping心跳检查 - 主动验证连接可用性


(由 ReconnectionOptionsExtension 定义。)
UseWebSocketCheckActionTClientReconnectionOptionTClient 设置一个基于活动时间与 Ping 的检查动作。
(由 ReconnectionOptionsExtension 定义。)
UseWebSocketCheckActionTClientReconnectionOptionTClient 设置一个基于活动时间与 Ping 的检查动作。
(由 ReconnectionOptionsExtension 定义。)

参见