private void RemoveClient(DeviceState device) { lock_list.Enter( ); list.Remove(device); device.WorkSocket?.Close( ); lock_list.Leave( ); ClientOffline?.Invoke(device); }
private void TcpStateDownLine(AppSession state, bool is_regular, bool logSave = true) { lockSessions.Enter( ); appSessions.Remove(state); lockSessions.Leave( ); // 关闭连接 TcpStateClose(state); // 判断是否正常下线 string str = is_regular ? StringResources.NetClientOffline : StringResources.NetClientBreak; ClientOffline?.Invoke(state, str); AllClientsStatusChange?.Invoke(ClientCount); // 是否保存上线信息 if (IsSaveLogClientLineChange && logSave) { LogNet?.WriteInfo(ToString(), $"[{state.IpEndPoint}] Name:{ state?.LoginAlias } { str }"); } }
private void TcpStateDownLine(AppSession state, bool is_regular) { HybirdLockSockets.Enter( ); All_sockets_connect.Remove(state); HybirdLockSockets.Leave( ); // 关闭连接 TcpStateClose(state); // 判断是否正常下线 string str = is_regular ? StringResources.NetClientOffline : StringResources.NetClientBreak; ClientOffline?.Invoke(state, str); // 是否保存上线信息 if (IsSaveLogClientLineChange) { LogNet?.WriteInfo(ToString(), "IP:" + state.IpAddress + " Name:" + state?.LoginAlias + " " + str); } // 计算客户端在线情况 AsyncCoordinator.StartOperaterInfomation( ); }
/// <summary> /// 关闭指定客户端 /// </summary> /// <param name="userID">客户端唯一的ID</param> /// <param name="normal">是否为正常断开</param> /// <param name="exception">异常类型</param> public void CloseClient(string userID, bool normal = true, Exception exception = null) { lock (lockObject) { if (clientCollection.ContainClient(userID)) { string ipEndPoint = clientCollection.GetClientIPEndPoint(userID).ToString(); if (clientCollection.RemoveClient(userID)) { ClientOffline?.Invoke(this, new ServerNotifyEventArgs(userID)); if (normal) { ServerMessage?.Invoke(this, new ServerNotifyEventArgs($"客户端 {userID}({ipEndPoint}) 断开连接")); return; } ServerMessage?.Invoke(this, new ServerNotifyEventArgs($"客户端 {userID}({ipEndPoint}) 意外的断开连接")); ServerError?.Invoke(this, new ServerErrorEventArgs(exception, $"客户端 {userID}({ipEndPoint}) 意外的断开连接")); } } } }