Files
wcs/WCS.BLL/Tool/DependencyExtensions.cs
hehaibing-1996 ac14b22507 1.前后端增加复位功能
2.tcpclient心跳设置
3.优化后端启动速度
4.增加后端出库日志
2024-05-28 17:48:48 +08:00

54 lines
1.5 KiB
C#

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
{
/// <summary>
/// 一个心跳计数器扩展。
/// </summary>
internal static class DependencyExtensions
{
public static readonly DependencyProperty<Timer> HeartbeatTimerProperty =
DependencyProperty<Timer>.Register("HeartbeatTimer", null);
public static bool Ping<TClient>(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<TClient>(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;
}
}
}