Skip to content

Bind local UDP port to the command station port#12

Merged
jaak0b merged 1 commit into
mainfrom
fix/bind-local-udp-port
Jun 27, 2026
Merged

Bind local UDP port to the command station port#12
jaak0b merged 1 commit into
mainfrom
fix/bind-local-udp-port

Conversation

@jaak0b

@jaak0b jaak0b commented Jun 27, 2026

Copy link
Copy Markdown
Owner

Problem

A regression since v6.0.3: the v7 UdpTransport lets the OS pick an ephemeral local UDP port, whereas 6.0.3 bound the local socket to the command station's port. Some Z21 firmware sends LAN_X_LOCO_INFO broadcasts to the command-station port (21105) rather than to the client's source port, so on an ephemeral local port those broadcasts are silently missed — system-state (sent to the source port) still arrives, but passive loco-info does not. Verified on hardware with Wireshark: loco-info packets were addressed to port 21105 / the controller's port, never to the ephemeral source port.

Change

  • UdpTransportOptions.LocalPort (int?): null (default) binds the command station's port — restoring the 6.0.3 behaviour; 0 keeps an OS-assigned ephemeral port; any other value binds that port.
  • UdpTransport.ConnectAsync binds LocalPort ?? RemoteEndPoint.Port.
  • Receive-path diagnostics at Debug: [RX] per datagram (UdpTransport), [FR] per append/emitted frame/partial/resync (Z21FrameReader), and [DISP] NO handler matched for frames no handler claims (Z21ResponseHandler).

Tests

  • New ConnectAsync_BindsConfiguredLocalPort asserts the transport sends from the configured local port.
  • Existing transport tests pin LocalPort = 0 (loopback harness needs an ephemeral local port). Full solution suite green.

@jaak0b jaak0b force-pushed the fix/bind-local-udp-port branch from 620cda1 to f5dc0e9 Compare June 27, 2026 19:13
@jaak0b jaak0b merged commit 46b321f into main Jun 27, 2026
5 checks passed
@jaak0b jaak0b deleted the fix/bind-local-udp-port branch June 27, 2026 19:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant