What is the best way to implement device discovery on a LAN
Asked Answered
N

1

13

I have little experience in network programming and I am writing a multi platform system which requires each device to be able to find other devices within the same LAN. I am looking for the right approach to do that, and hope that people here can give a good advise. Here are my design requirements:

  1. I am using C++ and the solution needs to be cross platform, which is at least able to run on iOS, Windows, Android.

  2. The system should be pretty light weight, and work under no special setup or network requirements, if possible.

Here are different approaches I am considering:

  1. Using uPnP protocol, but I am not very familiar with it, and it doesn't seems that there are many examples with code on the subject.

  2. Using the traditional socket approach, creating both Server/Client on each device and send the data packet to every IP in the LAN. And do everything manually afterwards. Correct me if I am wrong, if I send a packet to the broadcast address, does that mean that the system automatically sends my packet to every IP within the subnet?

  3. Using an external server all clients will register to, and then getting information about other(already registered) clients from that server. However, I am not sure with what information each client should connect in order to determine they are in the same LAN.

Let me know if what I am thinking makes any senses. Any advice is greatly appreciated.

Naamann answered 25/4, 2013 at 22:53 Comment(3)
It is common to send UDP packets to the broadcast address, with setup information for making a regular connection later. Packets sent to the broadcast will be sent to every device in that subnet. I recommend firing up Wireshark to see what happens behind the scenes.Rameriz
Thanks for the info, but I heard that the router can be setup up to stop the broadcast, and it is normally a default in a LAN. Is that true? And if yes, then such method is not quite reliable thenNaamann
No, the router goes between your network and another network. The broadcast packets are sent to your network only, so the router's configuration has no bearing on them. In addition, if a router were able to do this, your network would not function. Broadcast packets are important for basic functionality, such as DHCP, UPnP, and Bonjour (such as in Marko's answer).Rameriz
A
4

One option you have not listed is ZeroConf's DNS-SD protocol.

It is used heavily by Apple - who market it as Bonjour (née Rendezvous). There is tight integration into iOS and MacOSX.
Apple also provides a Windows implementation, an SDK and has open sourced the mDNS service.

Android appears to support it out of the box.

There's also robust and mature support for Linux in the form of Avahi, included in most desktop distros.

It seems the only platform where a user would need to install anything is Windows, and even then, it is installed with iTunes (used for music library sharing) and the setup software for any of Apple's wireless access points.

Audrey answered 25/4, 2013 at 23:26 Comment(1)
FYI - something to look out for: superuser.com/questions/730288/…Pallua

© 2022 - 2024 — McMap. All rights reserved.