|
|
|
@ -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 => |
|
|
|
var config = new TouchSocketConfig(); |
|
|
|
#region Http设置远程服务器地址
|
|
|
|
config.SetRemoteIPHost("http://" + url); |
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region Http客户端获取断线通知
|
|
|
|
config.ConfigurePlugins(a => |
|
|
|
{ |
|
|
|
options.PollingInterval = TimeSpan.FromSeconds(3); |
|
|
|
//处理连接断开
|
|
|
|
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(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
//处理连接
|
|
|
|
a.AddTcpConnectedPlugin(async (c, e) => |
|
|
|
#endregion
|
|
|
|
|
|
|
|
if (httpclient.Online)//是否重置客户端
|
|
|
|
{ |
|
|
|
await e.InvokeNext(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
#endregion
|
|
|
|
await httpclient.CloseAsync(); |
|
|
|
} |
|
|
|
|
|
|
|
if (httpclient.Online)//是否重置客户端
|
|
|
|
//配置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();
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|