So I am trying to send a packet once every 3 seconds and have tried using Schedule Executor service like this:
ScheduledExecutorService exec = Executors.newScheduledThreadPool(1);
exec.scheduleWithFixedDelay(new broadcast(), 0, 3, TimeUnit.SECONDS);
However to be able to send a packet an exception needs to be throw. I'm struggling to find a way to be able to throw this exception. I've tried encapsulating it in a try, catch statement but no luck.
static class broadcast implements Runnable{
    public void run() {
        Iterator iterator = hash.keySet().iterator();
        while(iterator.hasNext()){
            char c = iterator.next().toString().charAt(0);
            int[] a = hash.get(c);
            int sendPort = a[1];
            byte[] buffer = new byte[1024];
            buffer = linkState.toString().getBytes();
            System.out.println(a[0] + " " + a[1]);
            DatagramPacket sent = new DatagramPacket(buffer, buffer.length, sendAddress, sendPort);
            send(sent);  //this line here is the problem
        }
    }
}
private static void send(DatagramPacket sent) throws Exception{
    socket.send(sent);
}
Thanks for any help.
 
     
    