using EC.Util.Common; 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 int OnlineState { get; set; }//设备在线状态 public bool IsOnline { get { return Host != null && Host.Id >= 0 && OnlineState == 1; } } public ConcurrentDictionary SensorDict { get; } = new(); public int SensorTotal { get { return SensorDict.Count; } } public bool SensorsEmpty { get { return SensorDict == null || SensorDict.IsEmpty; } } public List DataList { get; } = new(); public string ClientAddr { get { return Client.ClientAddr(); } } public string ClientIp { get { if (Host != null) return Host.Ip; return Client.ClientIp(); } } public string ClientPort { get { if (Host != null) return Host.Port; return Client.ClientPort(); } } public string LocalAddr { get { return Client.LocalAddr(); } } public string LocalIp { get { return Client.LocalIp(); } } public string LocalPort { get { return Client.LocalPort(); } } #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; } }