Using UDP Broadcast Messages to Discover Local Clients

On my current project, we have a group of networked devices that will be assigning their own IP address semi-randomly based on a serial number burned into the CPU. This leaves us with a problem: we need to be able to quickly determine who’s on the network.

We’ve chosen to have each device listen on the network’s broadcast address using a UDP socket. We can then have our control device join the network and send a “Who’s there?” message to the broadcast address. When the devices on the network get the broadcast message, they respond with an “I’m here” message. Based on these responses, we can enumerate who all we should concern ourselves with in later operations.

There are a few special things to remember when configuring a system like this. I’ve built a pair of reference applications that define a listening broadcast “server” and a broadcast “client” that can discover who’s available.

I’ve made these sample applications available on Github.
 

Conversation
  • ygg says:

    Why don’t u use multicast instead of broadcast .
    It will again be broadcasted, but only to subscribers, and you won’t flood the network if it has lot’s of other nodes, non-interested in the traffic.

    • John Van Enk says:

      In my particular case, I’m using UDP broadcasts to discover a number of other participants on a local network. Once my nodes are discovered, I make connections to them over TCP. There’s no permanent coordinating node and it’s a purpose-built private network, so there’s no harm in using UDP (since really, no other traffic will be present).

      If I was using any sort of high-bandwidth setup, multicast would definitely be the way to go.

  • Comments are closed.