using System.Collections.Concurrent; using System.Net.Sockets; namespace JiLinApp.Docking.VibrateAlarm; public class ClientMessage { #region Fields public TcpClient Client { get; set; } public TcpAlarmHost Host { get; set; } public string Ip { get { if (Host != null) return Host.Ip; if (Client != null) return Client.Client.RemoteEndPoint.ToString().Split(':')[0]; return ""; } } public string Port { get { if (Host != null) return Host.Port; if (Client != null) return Client.Client.RemoteEndPoint.ToString().Split(':')[1]; return "-1"; } } public int OnlineState { get; set; }//设备在线状态 public int SensorTotal { get { return SensorDict.Count; } } public ConcurrentDictionary SensorDict { get; } = new(); public bool SensorsEmpty { get { return SensorDict == null || SensorDict.IsEmpty; } } public ReaderWriterLockSlim SensorsLock { get; } = new(); public List DataList { get; } = new(); #endregion Fields public ClientMessage() { } public void AddData(byte[] bytes) { DataList.AddRange(bytes); } public List GetMessageList() { List msglist = new(); while (DataList.Count >= 19) { if (DataList[0] == 0xAA && DataList[1] == 0xAA) { int num = DataList[17]; if (DataList.Count < 19 + num) break; byte[] bytes = new byte[num + 19]; for (int i = 0; i < bytes.Length; i++) { bytes[i] = DataList[i]; } msglist.Add(bytes); DataList.RemoveRange(0, num + 19); } else { DataList.RemoveAt(0); } } return msglist; } }