| 123456789101112131415161718192021222324252627282930313233343536373839404142 |
- using System;
- using System.Net.Sockets;
- namespace SWRIS.Models
- {
- public class ClientState
- {
- public string SerialNo { get; set; }
- public string IpAddress { get; }
- public Socket ClientSocket { get; set; }
- public byte[] Buffer { get; set; }
- public ByteCircularBuffer ReceiveBuffer { get; set; } = new ByteCircularBuffer(32768); // 添加环形缓冲区
- public DateTime LastActiveTime { get; set; } = DateTime.UtcNow;
- /// <summary>
- /// 最近一次收到有效数据(心跳包或业务数据包)的时间,从未收到过为 DateTime.MinValue
- /// </summary>
- public DateTime LastDataReceivedTime { get; set; } = DateTime.MinValue;
- /// <summary>
- /// 数据激活状态:数据超时窗口内收到过有效数据。
- /// 用于区分"链路在收发数据但心跳缺失"与"链路真正静默",
- /// 避免设备在持续上报实时数据时被判为离线。
- /// </summary>
- public bool IsDataActive { get; set; }
- /// <summary>
- /// 客户端是否已关闭,避免重复触发断开事件
- /// </summary>
- public bool IsClosed { get; set; }
- public ClientState(Socket clientSocket, string ipAddress, string serialNo)
- {
- ClientSocket = clientSocket;
- IpAddress = ipAddress;
- SerialNo = serialNo;
- Buffer = new byte[8192];
- }
- public ClientState(Socket clientSocket, string ipAddress)
- {
- ClientSocket = clientSocket;
- IpAddress = ipAddress;
- Buffer = new byte[8192];
- }
- }
- }
|