title: Sending UDP packet to everybody in a LAN?
body: <p>Is there a way to send a UDP packet inside a LAN so that every machine receives it? (Of course no guarantees because its UDP).</p>
  
  <p>Like, sending a request "Hello, anybody out there?" and then listening for a response?</p>
  
  <p>I got no problem with sending and receiving, just want to know if there's a way other than trying out every IP address possible...</p>
  
  <p><strong>Edit:</strong> This is what I use at the moment:</p>
  
  <pre><code>...
  multicastSocket = new MulticastSocket();
  multicastSocket.setBroadcast(true);
  broadcastGroup = InetAddress.getByName("255.255.255.255");
  // multicastSocket.joinGroup(broadcastGroup);
  ...
  </code></pre>
  
  <p>The last line of code is commented out because it throws an exception. Now I've read that sending a packet to 255.255.255.255 is "deprecated since years" and most likely won't work on many LANs. Also, I'm not sure if I even need a <code>MulticastSocket</code> for this or if a normal <code>DatagramSocket</code> would work as well. But anyway, what would be the preferred way to send a UDP broadcast nowadays?</p>