This commit is contained in:
Administrator committed 2026-06-12 22:28:49 +08:00
commit 94d1fb6a5d
8 files changed
+81 -48

No files matched your search

+48 -38
View File
@@ -40,52 +40,62 @@ namespace SunlightAggregationTerminal.Class
else
{
await HttpClient(DataReceived.ServerIP);
HttpTransmit("{\"Command\":\"Log\"}");
}
}
public static async Task HttpClient(string url)
{
var config = new TouchSocketConfig();
#region Http设置远程服务器地址
config.SetRemoteIPHost("http://" + url);
#endregion
#region Http客户端获取断线通知
config.ConfigurePlugins(a =>
try
{
//处理连接断开
a.AddTcpClosedPlugin(async (c, e) =>
{
//MainThread.BeginInvokeOnMainThread(() =>
// {
// Application.Current!.Windows[0].Page!.DisplayAlertAsync("", "客户端断开连接", "是");
// });
// await e.InvokeNext();
});
//自动重连
a.UseReconnection<TouchSocket.Http.HttpClient>(options =>
{
options.PollingInterval = TimeSpan.FromSeconds(3);
});
//处理连接
a.AddTcpConnectedPlugin(async (c, e) =>
{
await e.InvokeNext();
});
});
#endregion
var config = new TouchSocketConfig();
#region Http设置远程服务器地址
config.SetRemoteIPHost("http://" + url);
#endregion
if (httpclient.Online)//是否重置客户端
#region Http客户端获取断线通知
config.ConfigurePlugins(a =>
{
//处理连接断开
a.AddTcpClosedPlugin(async (c, e) =>
{
//MainThread.BeginInvokeOnMainThread(() =>
// {
// Application.Current!.Windows[0].Page!.DisplayAlertAsync("", "客户端断开连接", "是");
// });
// await e.InvokeNext();
});
//自动重连
a.UseReconnection<TouchSocket.Http.HttpClient>(options =>
{
options.PollingInterval = TimeSpan.FromSeconds(3);
});
//处理连接
a.AddTcpConnectedPlugin(async (c, e) =>
{
await e.InvokeNext();
});
});
#endregion
if (httpclient.Online)//是否重置客户端
{
await httpclient.CloseAsync();
}
//配置config
await httpclient.SetupAsync(config);
//连接
await httpclient.ConnectAsync();
HttpTransmit("{\"Command\":\"Log\"}");
}
catch (Exception ex)
{
await httpclient.CloseAsync();
MainThread.BeginInvokeOnMainThread(() =>
{
Application.Current!.Windows[0].Page!.DisplayAlertAsync("网络错误", ex.Message.ToString(), "是");
});
}
//配置config
await httpclient.SetupAsync(config);
//连接
await httpclient.ConnectAsync();
}
/***发送信息处理***/
@@ -142,7 +152,7 @@ namespace SunlightAggregationTerminal.Class
}
finally
{
Start();
//Start();
}
}