fix: add udpClient behavior to throttle receive errors and reset upon valid traffic arrival

This commit is contained in:
Jonathan Arndt 2026-05-15 13:45:50 -07:00
parent d47cfd5e62
commit 18f7000d76

View file

@ -23,6 +23,7 @@ namespace PepperDash.Core
private UdpClient client; private UdpClient client;
private CancellationTokenSource receiveCancellationTokenSource; private CancellationTokenSource receiveCancellationTokenSource;
private bool connectEnabled; private bool connectEnabled;
private bool connectionRefusedLogged;
private SocketStatus clientStatus = SocketStatus.SOCKET_STATUS_NO_CONNECT; private SocketStatus clientStatus = SocketStatus.SOCKET_STATUS_NO_CONNECT;
/// <summary> /// <summary>
@ -367,6 +368,8 @@ namespace PepperDash.Core
if (bytes == null || bytes.Length == 0) if (bytes == null || bytes.Length == 0)
continue; continue;
connectionRefusedLogged = false;
var text = Encoding.GetEncoding(28591).GetString(bytes, 0, bytes.Length); var text = Encoding.GetEncoding(28591).GetString(bytes, 0, bytes.Length);
this.PrintReceivedBytes(bytes); this.PrintReceivedBytes(bytes);
@ -385,6 +388,20 @@ namespace PepperDash.Core
} }
catch (NetSocketException ex) catch (NetSocketException ex)
{ {
if (ex.SocketErrorCode == SocketError.ConnectionRefused)
{
if (!connectionRefusedLogged)
{
Debug.Console(1, Debug.ErrorLogLevel.Warning,
"GenericUdpClient '{0}': Remote endpoint refused UDP traffic or is no longer listening",
Key);
connectionRefusedLogged = true;
}
HandleDisconnected();
return;
}
Debug.LogMessage(ex, "UDP receive error for {0}", this, Key); Debug.LogMessage(ex, "UDP receive error for {0}", this, Key);
if (AutoReconnect) if (AutoReconnect)