Detect tcp disconnection
- Dominant language
- C#
- Stars
- 2.4k
- Forks
- 416
- PR merge metrics
- No merged PRs in 30d
Description
Hi, I'm using System.MonitorEventsAsync and connecting to a tcp socket.
Sometimes the machine I'm connecting to is restarted and I lose connection, how can I detect this and reconnect?
```c#
private async Task StartDockerClient(CancellationToken cancellationToken)
{
Credentials credentials = null;
if (dockerHostSettings.Username is not null && dockerHostSettings.Password is not null)
{
credentials = new Docker.DotNet.BasicAuth.BasicAuthCredentials(dockerHostSettings.Username, dockerHostSettings.Password, dockerHostSettings.UseTls);
}
client = new DockerClientConfiguration(
endpoint: new Uri(dockerHostSettings.Endpoint),
credentials: credentials
).CreateClient();
var progress = new Progress();
progress.ProgressChanged += Progress_ProgressChanged;
IList containers = await client.Containers.ListContainersAsync(
new ContainersListParameters()
{
Filters = new Dictionary>()
{
{
"status",
new Dictionary()
{
{ "running", true }
}
},
}
}
);
foreach (var item in containers)
{
var container = await GetContainer(item);
if (container is null) { continue; }
await (ContainerStarted?.Invoke(container) ?? Task.CompletedTask);
}
client.System.MonitorEventsAsync(new ContainerEventsParameters(), progress, cancellationToken);
}
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.