internal void OnHeartbeat(long timeout) { if (this.PingTimeoutTimer != null) { PingTimeoutTimer.Stop(); PingTimeoutTimer = null; } if (timeout <= 0) { timeout = this.PingInterval + this.PingTimeout; } PingTimeoutTimer = EasyTimer.SetTimeout(() => { var log2 = LogManager.GetLogger(GlobalHelper.CallerName()); log2.Info("EasyTimer OnHeartbeat start"); if (ReadyState == ReadyStateEnum.CLOSED) { log2.Info("EasyTimer OnHeartbeat ReadyState == ReadyStateEnum.CLOSED finish"); return; } OnClose("ping timeout"); log2.Info("EasyTimer OnHeartbeat finish"); }, (int)timeout); }
private void SetPing() { var log = LogManager.GetLogger(GlobalHelper.CallerName()); if (this.PingIntervalTimer != null) { PingIntervalTimer.Stop(); } log.Info(string.Format("writing ping packet - expecting pong within {0}ms", PingTimeout)); PingIntervalTimer = EasyTimer.SetTimeout(() => { var log2 = LogManager.GetLogger(GlobalHelper.CallerName()); log2.Info("EasyTimer SetPing start"); Ping(); OnHeartbeat(PingTimeout); log2.Info("EasyTimer SetPing finish"); }, (int)PingInterval); }