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
try
while (true)
{
await tcpClient.SetupAsync(new TouchSocketConfig()
.SetSingleStreamDataHandlingAdapter(() => new PeriodPackageAdapter())//以超时周期和包
.SetRemoteIPHost(ip)
.ConfigurePlugins(a =>
{
a.UseReconnection<TouchSocket.Sockets.TcpClient>(options =>
try
{
await tcpClient.SetupAsync(new TouchSocketConfig()
.SetSingleStreamDataHandlingAdapter(() => new PeriodPackageAdapter())//以超时周期和包
.SetRemoteIPHost(ip)
.ConfigurePlugins(a =>
{
options.PollingInterval = TimeSpan.FromSeconds(5);
});
})
.ConfigureContainer(a =>
{
}));
a.UseReconnection<TouchSocket.Sockets.TcpClient>(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)

Loading…
Cancel
Save