I am making a nice multiplayer application but I want my application to search for hosts in you lan. I know that you can obtain your own IP quite easily and then brute force all IPs to see if anything is connected, but this is both quite hard work for your computer and it takes a some time as well even when you multithread it properly.
There seems to be no good way to obtain the arp table in java but I hope there is something similar where you can obtain all local IP-addresses fast and efficient.
Any help would be much appreciated.Answer1:
Several options exists and can be used to achieve this.
<strong>The decentralized one</strong>
What you could do is <a href="https://en.wikipedia.org/wiki/Broadcasting_%28networking%29" rel="nofollow"><em>broadcasting</em></a> a request from your application that asks every hosts on the network if they are currently available for a game (sending the request on
255.255.255.255 for instance, will cause your router to retransmit the datagrams you sent to every host on a LAN).
This will ensure that only the hosts that have the game launched and which are ready to play will respond to this request.
Several broadcasting protocols are today heavily used on a LAN. One of them is <a href="http://fr.wikipedia.org/wiki/Simple_Service_Discovery_Protocol" rel="nofollow">SSDP (Simple Service Discovery Protocol)</a> which is used with the UPnP protocol for service discovery. There are certainly better suited protocols used over broadcast/multicast for multiplayer games though.
<strong>The centralized one</strong>
One of the commonest way to discover players on a multiplayer game remains in the presence of a central server on which both <em>requester</em> (people who are looking for a game) and <em>hosters</em> (people who are hosting a game) are connected.
This method has the disadvantage of having a single point of failure, which is the server, but has the advantage, unlike the decentralized solution, of being both suitable for a LAN and for Internet (or every IP based protocol).
If I had to develop a multiplayer game this is where I would start digging regarding the host discovery feature you are required to implement.