diff --git a/UserClass/AsyncTcpClient.cs b/UserClass/AsyncTcpClient.cs index 6f955fd..3fa0c67 100644 --- a/UserClass/AsyncTcpClient.cs +++ b/UserClass/AsyncTcpClient.cs @@ -137,31 +137,38 @@ namespace SunlightAggregationManager.UserClass }; #endregion - try + while (true) { - await tcpClient.SetupAsync(new TouchSocketConfig() - .SetSingleStreamDataHandlingAdapter(() => new PeriodPackageAdapter())//以超时周期和包 - .SetRemoteIPHost(ip) - .ConfigurePlugins(a => - { - a.UseReconnection(options => + try + { + await tcpClient.SetupAsync(new TouchSocketConfig() + .SetSingleStreamDataHandlingAdapter(() => new PeriodPackageAdapter())//以超时周期和包 + .SetRemoteIPHost(ip) + .ConfigurePlugins(a => { - options.PollingInterval = TimeSpan.FromSeconds(5); - }); - - }) - .ConfigureContainer(a => - { - - })); + a.UseReconnection(options => + { + options.PollingInterval = TimeSpan.FromSeconds(5); + }); - await tcpClient.ConnectAsync();//调用连接,当连接不成功时,会抛出异常。 + }) + .ConfigureContainer(a => + { - } - catch (Exception ex) - { - LogGing.ERRDATA(ex); - Console.WriteLine("Tcp:" + ex.ToString()); + })); + + await tcpClient.ConnectAsync();//调用连接,当连接不成功时,会抛出异常。 + break; + + } + 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)