ensure closing of datagram socket in arcane Util

This commit is contained in:
Marc Zwart 2018-03-20 14:59:41 +01:00
parent 63dbfb8a9b
commit 338e9833cc

View file

@ -37,9 +37,13 @@ public final class Util {
}
public static void broadcast(byte[] data, int port) throws IOException {
DatagramSocket socket = new DatagramSocket();
broadcast(socket, data, port, NetworkInterface.getNetworkInterfaces());
socket.close();
DatagramSocket socket = null;
try {
socket = new DatagramSocket();
broadcast(socket, data, port, NetworkInterface.getNetworkInterfaces());
} finally {
socket.close();
}
}
private static void broadcast(DatagramSocket socket, byte[] data, int port, Enumeration<NetworkInterface> ifaces)