using System.Collections; using System.Net.Sockets; namespace JiLinApp.Docking.VibrateAlarm; public class ClientMessage { #region Fields public TcpClient Client { get; set; } public TcpAlarmHostTable Host { get; set; } public List DataList { get; } = new(); public Hashtable SectionTable { get; } = new(); public List SensorList { get; set; } public bool SensorListEmpty { get { return SensorList == null || SensorList.Count == 0; } } public ReaderWriterLockSlim SensorListLock { get; } = new(); 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"; } } #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; } }