This commit is contained in:
Administrator committed 2026-06-06 00:29:45 +08:00
commit e0c949bde9
4 files changed
+92 -46

No files matched your search

+23 -21
View File
@@ -40,6 +40,8 @@ namespace SunlightAggregationTerminal.Class
else
{
await HttpClient(DataReceived.ServerIP);
HttpTransmit("{\"Command\":\"Log\"}");
}
}
@@ -53,30 +55,26 @@ namespace SunlightAggregationTerminal.Class
#region Http客户端获取断线通知
config.ConfigurePlugins(a =>
{
//处理连接断开
a.AddTcpClosedPlugin(async (c, e) =>
{
// 专门处理超时或主动取消的情况
MainThread.BeginInvokeOnMainThread(() =>
{
Application.Current!.Windows[0].Page!.DisplayAlertAsync("", "客户端断开连接", "是");
});
await e.InvokeNext();
//MainThread.BeginInvokeOnMainThread(() =>
// {
// Application.Current!.Windows[0].Page!.DisplayAlertAsync("", "客户端断开连接", "是");
// });
// await e.InvokeNext();
});
}); config.ConfigurePlugins(a =>
{
a.AddTcpConnectedPlugin(async (c, e) =>
{
HttpTransmit("{\"Command\":\"Log\"}");
await e.InvokeNext();
});
});
/*config.ConfigurePlugins(a =>
{
//自动重连
a.UseReconnection<TouchSocket.Http.HttpClient>(options =>
{
options.PollingInterval = TimeSpan.FromSeconds(3);
});
});*/
//处理连接
a.AddTcpConnectedPlugin(async (c, e) =>
{
await e.InvokeNext();
});
});
#endregion
if (httpclient.Online)//是否重置客户端
@@ -93,6 +91,10 @@ namespace SunlightAggregationTerminal.Class
/***发送信息处理***/
public static async void HttpTransmit(string Dat)
{
if(!httpclient.Online) //检查连接
{
await httpclient.ConnectAsync();
}
var dat = new DataReceived.Person()
{
User = DataReceived.ServerName,
@@ -119,6 +121,7 @@ namespace SunlightAggregationTerminal.Class
// GetBodyAsync 同样需要响应取消信号,如果这里超过剩余时间也会抛出异常
var result = await response.GetBodyAsync();
DataReceived.Received(result);
//await httpclient.CloseAsync();//关闭客户端
}
}
catch (OperationCanceledException)
@@ -126,8 +129,9 @@ namespace SunlightAggregationTerminal.Class
// 专门处理超时或主动取消的情况
MainThread.BeginInvokeOnMainThread(() =>
{
Application.Current!.Windows[0].Page!.DisplayAlertAsync("网络错误", "网络请求超时,请检查网络或服务器状态。", "是");
Application.Current!.Windows[0].Page!.DisplayAlertAsync("网络错误", "网络请求超时,请检查网络网络连接", "是");
});
await httpclient.CloseAsync();//关闭客户端
}
catch (Exception ex)
{
@@ -136,9 +140,7 @@ namespace SunlightAggregationTerminal.Class
Application.Current!.Windows[0].Page!.DisplayAlertAsync("网络错误", ex.Message.ToString(), "是");
});
}
}
}
}