Administrator 3 weeks ago
committed by 忱 沈
parent
commit
a0eeb9c8c4
  1. 49
      UserClass/AsyncTcpClient.cs

49
UserClass/AsyncTcpClient.cs

@ -137,31 +137,38 @@ namespace SunlightAggregationManager.UserClass
}; };
#endregion #endregion
try while (true)
{ {
await tcpClient.SetupAsync(new TouchSocketConfig() try
.SetSingleStreamDataHandlingAdapter(() => new PeriodPackageAdapter())//以超时周期和包 {
.SetRemoteIPHost(ip) await tcpClient.SetupAsync(new TouchSocketConfig()
.ConfigurePlugins(a => .SetSingleStreamDataHandlingAdapter(() => new PeriodPackageAdapter())//以超时周期和包
{ .SetRemoteIPHost(ip)
a.UseReconnection<TouchSocket.Sockets.TcpClient>(options => .ConfigurePlugins(a =>
{ {
options.PollingInterval = TimeSpan.FromSeconds(5); a.UseReconnection<TouchSocket.Sockets.TcpClient>(options =>
}); {
options.PollingInterval = TimeSpan.FromSeconds(5);
}) });
.ConfigureContainer(a =>
{
}));
await tcpClient.ConnectAsync();//调用连接,当连接不成功时,会抛出异常。 })
.ConfigureContainer(a =>
{
} }));
catch (Exception ex)
{ await tcpClient.ConnectAsync();//调用连接,当连接不成功时,会抛出异常。
LogGing.ERRDATA(ex); break;
Console.WriteLine("Tcp:" + ex.ToString());
}
catch (Exception ex)
{
tcpClient.Dispose();//清
LogGing.ERRDATA(ex);
Console.WriteLine("Tcp:" + ex.ToString());
await Task.Delay(TimeSpan.FromMinutes(1));
Console.WriteLine("Tcp:重试连接...");
}
} }
} }
private static void TimerCallback(object? state) private static void TimerCallback(object? state)

Loading…
Cancel
Save