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