This commit is contained in:
Administrator committed 2026-06-03 00:30:52 +08:00
commit 751bbe5199
1 file changed
+18 -3
+18 -3
View File
@@ -7,7 +7,6 @@ using System.Text.Json;
using TouchSocket.Core;
using TouchSocket.Sockets;
using static SunlightAggregationManager.UserClass.AsyncTcpServer;
using static System.Runtime.InteropServices.JavaScript.JSType;
namespace SunlightAggregationManager.UserClass
{
@@ -58,7 +57,16 @@ namespace SunlightAggregationManager.UserClass
Console.WriteLine("Sunlight_Server_Connected");
return EasyTask.CompletedTask;
};//成功连接到服务器
tcpClient.Closing = (client, e) => { return EasyTask.CompletedTask; };//即将从服务器断开连接。此处仅主动断开才有效。
tcpClient.Closing = (client, e) => {
System.Data.DataRow targetRow = ViewModel.MainWindowViewModel._service.Select("Service = 'Sunlight_Server_Link'").FirstOrDefault()!;
if (targetRow != null)
{
targetRow.BeginEdit();
targetRow["Status"] = "Disconnect";
targetRow.EndEdit();
}
Console.WriteLine("Sunlight_Server_Disconnect");
return EasyTask.CompletedTask; };//即将从服务器断开连接。此处仅主动断开才有效。
tcpClient.Closed = (client, e) => {
System.Data.DataRow targetRow = ViewModel.MainWindowViewModel._service.Select("Service = 'Sunlight_Server_Link'").FirstOrDefault()!;
if (targetRow != null)
@@ -130,7 +138,7 @@ namespace SunlightAggregationManager.UserClass
{
a.UseReconnection<TouchSocket.Sockets.TcpClient>(options =>
{
options.PollingInterval = TimeSpan.FromSeconds(5);
options.PollingInterval = TimeSpan.FromSeconds(3);
});
}));
@@ -145,6 +153,7 @@ namespace SunlightAggregationManager.UserClass
public static async void CommandC(string dat, Person person)//
{
try {
string Command = "", ret = "";
Dictionary<string, object> data_ = new Dictionary<string, object>();
@@ -208,6 +217,12 @@ namespace SunlightAggregationManager.UserClass
person!.Dat = ret.ToString();
var jsdat = JsonSerializer.Serialize(person);
await tcpClient.SendAsync(jsdat);
}
catch (Exception ex)
{
LogGing.ERRDATA(ex);
Console.WriteLine(ex.ToString());
}
}
}
}