You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
73 lines
1.7 KiB
73 lines
1.7 KiB
1 year ago
|
using System.Collections;
|
||
|
using System.Net.Sockets;
|
||
|
|
||
|
namespace JiLinApp.Docking.VibrateAlarm;
|
||
|
|
||
|
public class ClientMessage
|
||
|
{
|
||
|
public TcpClient client { get; set; }
|
||
|
|
||
|
public TcpAlarmHostTable 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 List<byte> list { get; set; }
|
||
|
|
||
|
public Hashtable sectioTable { get; set; }
|
||
|
|
||
|
public ClientMessage()
|
||
|
{
|
||
|
list = new List<byte>();
|
||
|
host = null;
|
||
|
sectioTable = new Hashtable();
|
||
|
}
|
||
|
|
||
|
public List<byte[]> getMessageList()
|
||
|
{
|
||
|
List<byte[]> msglist = new List<byte[]>();
|
||
|
while (list.Count >= 19)
|
||
|
{
|
||
|
if (list[0] == 0xAA && list[1] == 0xAA)
|
||
|
{
|
||
|
int num = list[17];
|
||
|
if (list.Count < 19 + num)
|
||
|
{
|
||
|
break;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
byte[] bytes = new byte[num + 19];
|
||
|
for (int i = 0; i < bytes.Length; i++)
|
||
|
{
|
||
|
bytes[i] = list[i];
|
||
|
}
|
||
|
msglist.Add(bytes);
|
||
|
list.RemoveRange(0, num + 19);
|
||
|
}
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
list.RemoveAt(0);
|
||
|
}
|
||
|
}
|
||
|
return msglist;
|
||
|
}
|
||
|
}
|