using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using TouchSocket.Core; using TouchSocket.Sockets; namespace WCS.BLL.Tool { /// /// 一个心跳计数器扩展。 /// internal static class DependencyExtensions { public static readonly DependencyProperty HeartbeatTimerProperty = DependencyProperty.Register("HeartbeatTimer", null); public static bool Ping(this TClient client) where TClient : ITcpClientBase { try { var data = new byte[] { 0x05, 0x00, 0x00, 0x06, 0x78, 0x12, 0x34, 0x56, 0x78, 0x00, 0x00, 0x00, 0x00 }; client.Send(data); return true; } catch (Exception ex) { Logs.Write($"【{client.IP}:{client.Port}】发送心跳中发现异常:" + ex.Message, LogsType.Info); if (ex is NotConnectedException) { } } return false; } public static bool Pong(this TClient client) where TClient : ITcpClientBase { try { client.Send(new MyRequestInfo() { DataType = DataType.Pong }.PackageAsBytes()); return true; } catch (Exception ex) { client.Logger.Exception(ex); } return false; } } }