Broadcasts on a 802.11 Wifi network

Continuing the discussion from Building a LIFX packet:

I had to learn this one the hard way, so I’m glad to be able to pass on the knowledge. The answer has to do with the way broadcasts are handled in an 802.11 Wifi networks.

So in a wireless network there is no way to avoid broadcasting because you have to share the frequency with all the other clients around you. So technically every message is a broadcast. So originally I thought that Wifi broadcasts would work pretty much the same way. Turns out its a little bit more complicated than that.

Consider this network:

Now if the phone were to do the broadcast only the red bulb would be able to see it, but the green bulb would not. The only thing that they all can see is the AP in the middle. So instead what happens is that the phone will transmit the broadcast to the AP. The AP stores this broadcast, then after the next beacon in a DTIM message it sets a flag to let all the clients know that there is broadcast data available. Actually it might not happen every broadcast, there is a setting in most routers called the DTIM interval, which defines how often the DTIM message is sent. Once a client sees this flag in the DTIM message it will send a request to the AP for the buffered data, and the AP will return it. Also if the AP sees too many broadcasts it will run out of buffer space to store them and have to drop them.

So this means that a broadcast has to wait until the next DTIM interval to pass, then wait for each client to ask for the data, then finally for the AP to return it. So the broadcast will arrive at each client at a slightly different time. It is also why the LIFX applications will try to avoid broadcast packets as much as possible, because they tend to be largely unreliable.

All this is so that low power clients only have to turn their radios on when the DTIM interval arrives. So if you want to save battery for your wireless devices, set the DTIM interval high, if you want reliable broadcasts, set it low.

If you want to read about things like this yourself, you can read the 802.11n specification from the IEEE.

/cc @rasputin303 @darrenr

Thank you for that very clear explanation Daniel! Took me a long time to work this out as well, very ‘light bulb’ moment for me :smile: