There is very little information on the internet on how to send broadcast UDP messages in Java, which is kind of surprising since UDP broadcast is the simplest way to do broadcast messages without having to write a lot of code and or put in a lot of moving pieces, so long as one is aware of the drawbacks. I found myself having to search for this information and even Oracle's own documentation on this is just mediocre at best. Fortunately, someone took the time to write down. This is just a mirror of that information on GitHub to make it easier to find for someone searching for the same information.
- Import some needed classes
import sun.net.*;
import java.net.*;
- Declare the port we send to