Search code examples
udpwifibroadcastmulticast

What's the difference between sending a UDP datagram to an IP address over WIFI and broadcasting over WIFI when only one WIFI client is connected?


I'm experimenting with WIFI multicasting and broadcasting using Raspberry PIs as clients. If I subnet-broadcast or multicast over the WIFI then I lose a lot of packets. If I 'broadcast' to the specific IP of the receiver then I don't lose any packets. I have only the 1 receiver/client connected to my WIFI AP. I'm using QT framework's QUDPSocket::writeDatagram. So I just have to set the IP there and broadcast/subnet-broadcast/multicast is inherently selected. I have verified the appropriate MAC addresses are set using Wireshark and everything seems correct. I can't understand why I'm getting such a huge difference in performance. It's all UDP and there's only a single WIFI client. Any ideas please?

Edit in response to Sam Mason: QUDPSocket::writeDatagram takes an IP address. That IP address dictates whether you are unicasting, multicasting, broadcasting, or sub-net-broadcasting. I'm looping on this call to achieve a fixed tx speed of 1.5Mbps. (this is slow compared to what I should be able to push across my WIFI network so I'm not asking for a lot). My question really is why should unicast drop zero packets whilst all other methods drops lots of packets. I'm aware of the 'lowest common denominator' aspect of non-unicast but I only have 1 client connected, so...what does that mean?). I'm really after a nuts-and-bolts explanation of the real difference between UDP unicast and UDP-broadcast-with-single-client-connected.


Solution

  • The short answer is: You are seeing artifacts of implementation details of your specific WLAN router. Other routers may or may not behave differently.

    Details:

    WLAN uses two general modes of communication on the link layer: Individually addressed or group addressed.

    For 1:1 communication it uses individually addressed communication and this is made robust by acknowledges and retransmissions on the link layer. This is used for unicast UDP and for TCP etc.

    For one to many communication it uses group addresses frames and there is no protection against packet loss at all on the link layer. In addition, in this mode the router may fall back to the slowest WLAN transfer rate (1MBits/s) to make sure every STA can receive it.

    Now the WLAN router has some freedom which mode it uses for which IP packet:

    Any packet (unicast/multicast/broadcast) from sender to WLAN router: Individually addressed. This is always a 1:1 relationship (one sender to one router).

    UDP unicast and TCP etc: It uses individually addressed frames to send to the target STA. No packet loss. High speed.

    UDP multicast: Some WLAN routers (actually this is quite common) are smart and still use individually addressed frames when only one client has registered to receive this multicast group via IGMP. When multiple STAs want to receive the multicast frames it will most likely use group addresses (with visible packet loss). The router has the freedom to choose the data rate. Usually it will use a high data rate, not the 1 MBs fallback.

    UDP broadcast: Most WLAN routers will blindly use group addressed (with visible packet loss) and will use the 1MB/s fallback data rate as the lowest common denominator.

    UDP mutlicast and UDP broadcast over WLAN behaves very different from UDP multicast and UDP broadcast over ethernet. You have to expect lots of artifacts, packet loss, reordered packets, very slow data rate.

    The above explains why you see lots of lost packets when firing 1.5 MB/s broadcasts over the slow 1MB/s group address link using the 1 MB/s fallback data rate.