Fix of #7 tried to set DualMode on IPv4 network

This commit is contained in:
2025-02-06 17:02:52 +01:00
parent 5b8a2a8af1
commit 885231466b
3 changed files with 34 additions and 93 deletions

View File

@@ -108,7 +108,10 @@ namespace AMWD.Protocols.Modbus.Tcp
_stopCts?.Dispose();
_stopCts = new CancellationTokenSource();
_tcpListener.Socket.DualMode = ListenAddress.AddressFamily == AddressFamily.InterNetworkV6;
// Only allowed to set, if the socket is in the InterNetworkV6 address family.
// See: https://learn.microsoft.com/en-us/dotnet/api/system.net.sockets.socket.dualmode?view=netstandard-2.0#exceptions
if (ListenAddress.AddressFamily == AddressFamily.InterNetworkV6)
_tcpListener.Socket.DualMode = true;
_tcpListener.Start();
_clientConnectTask = WaitForClientAsync(_stopCts.Token);