/// <summary> /// 客户端下线处理 callback /// </summary> /// <param name="ClientID">客户端ID</param> public void ClientDisconnect(object sender, ClientEventArg arg) { string ClientID = arg.ClientID; LOG.Error(string.Format("客户端:{0}下线", ClientID)); /*Redundancy _redundancy = ResourceManager.GetRedundancy(); * _redundancy.OnDisconnectFromPartner();*/ }
/// <summary> /// 检查心跳 /// </summary> private void CheckHeartBeat(object sender) { lock (_hbRecordLocker) { try { string removedClient = null; foreach (string client in _hbRecord.Keys) { DateTime time = _hbRecord[client]; if (DateTime.Now.Subtract(time) > HBTimeout && _missingHBHandlers != null) { //这里出发丢失心跳事件 ClientEventArg arg = new ClientEventArg(client, ClientEventType.MissHeartBeat); _missingHBHandlers(this, arg); removedClient = client; } } if (removedClient != null) { //这里发出客户端下线事件 ClientEventArg arg = new ClientEventArg(removedClient, ClientEventType.Disconnect); _disconnectHandlers(this, arg); RemoveClient(removedClient); LOG.Error(string.Format("删除客户端:{0}", removedClient)); } } catch (Exception ex) { LOG.Error(string.Format("检测心跳出错:{0}", ex.Message)); } } }
/// <summary> /// 客户端连接超时处理 callback /// </summary> /// <param name="ClientID">客户端ID</param> public void HeartbeatTimeout(object sender, ClientEventArg arg) { string ClientID = arg.ClientID; LOG.Error(string.Format("客户端:{0}连接超时", ClientID)); }
/// <summary> /// 心跳处理 /// </summary> public void HeartBeat(object sender, ClientEventArg arg) { LOG.Error(string.Format("客户端心跳处理")); }
/// <summary> /// 客户端下线处理 callback /// </summary> public void ClientDisconnect(object sender, ClientEventArg arg) { var clientId = arg.ClientID; Log.Error($"客户端:{clientId}下线"); }
/// <summary> /// 客户端连接超时处理 callback /// </summary> public void HeartbeatTimeout(object sender, ClientEventArg arg) { var clientId = arg.ClientID; Log.Error($"客户端:{clientId}连接超时"); }
/// <summary> /// 心跳处理 /// </summary> public void HeartBeat(object sender, ClientEventArg arg) { Log.Error("客户端心跳处理"); }