Asymmetric UDP LAN discovery in Rust (Windows ↔ Linux) – broadcast received only one way

I’m implementing LAN peer discovery in Rust using UDP broadcast (Tokio).

Setup

  • Windows + Fedora Linux
  • Same Wi-Fi network
  • UDP port 7777
  • tokio::net::UdpSocket

Issue

  • :white_check_mark: Linux can discover Windows
  • :cross_mark: Windows cannot discover Linux
    So discovery only works one way.

Broadcast sender:

let socket = UdpSocket::bind("0.0.0.0:0").await?;
socket.set_broadcast(true)?;
socket.send_to(b"COPYD_DISCOVER", "255.255.255.255:7777").await?;

Listener:

let socket = UdpSocket::bind("0.0.0.0:7777").await?;
socket.set_broadcast(true)?;

let (size, addr) = socket.recv_from(&mut buffer).await?;
if &buffer[..size] == b"COPYD_DISCOVER" {
    socket.send_to(b"COPYD_PEER", addr).await?;
}

Checks done

  • Windows Defender firewall allows UDP
  • Fedora firewall allows UDP 7777
  • No VPN, same subnet

Questions

  1. Is 255.255.255.255 unreliable for Windows → Linux discovery?
  2. Should I send subnet-directed broadcasts (e.g. 192.168.x.255) instead?
  3. Are there OS differences in handling UDP broadcast with Tokio?
  4. What’s the recommended cross-platform LAN discovery pattern in Rust?

Any guidance from people who’ve done cross-platform UDP discovery would help a lot. Thanks!

everything seems correct try to double check the windows firewall settings my only guess right now is that the packet gets blocked there

Thanks for the suggestion. I double-checked the firewall configuration and ran a few additional tests.

  • I tested discovery between two Windows machines → they discover each other correctly.
  • I tested Windows ↔ Linuxdiscovery fails on the Windows side (Windows cannot discover Linux).
  • I verified basic UDP connectivity using ncat:
    • Windows → Linux works
    • Linux → Windows works
  • Windows Defender firewall rules are in place and appear to be working correctly.

Since raw UDP communication works in both directions and Windows-to-Windows discovery is fine, this doesn’t seem to be a Windows firewall issue.

This makes me suspect a difference in how Linux handles incoming UDP broadcast packets (e.g. 255.255.255.255) or how Windows sends them toward Linux.

I can’t replicate the problem you’re having, with either your “listener” code on my Linux laptop, or with commands like ncat -v -c 'echo -n COPYD_PEER' -k -u -l 7777 which should do exactly the same. I’m using PowerShell for the Windows side, though, since I don’t have a working Windows dev environment right now.

Some things I would try would be:

  • Add more logging to your code to make sure that you’re right about what’s happening at each end.
  • Use Wireshark or something like that to confirm what UDP network traffic each end is seeing.
  • Try replacing the code at each end with something different, like ncat, PowerShell, etc., one at a time.

Have you tested two Linux machines too?