diff options
Diffstat (limited to 'same/src/main/java/com/orbekk')
-rw-r--r-- | same/src/main/java/com/orbekk/net/BroadcastListener.java | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/same/src/main/java/com/orbekk/net/BroadcastListener.java b/same/src/main/java/com/orbekk/net/BroadcastListener.java index c0b66e0..8c59300 100644 --- a/same/src/main/java/com/orbekk/net/BroadcastListener.java +++ b/same/src/main/java/com/orbekk/net/BroadcastListener.java @@ -11,14 +11,14 @@ import org.slf4j.LoggerFactory; public class BroadcastListener { private int port; private Logger logger = LoggerFactory.getLogger(getClass()); + DatagramSocket socket; public BroadcastListener(int port) { this.port = port; } - public DatagramPacket listen() { + public synchronized DatagramPacket listen() { logger.debug("Waiting for broadcast on port " + port); - DatagramSocket socket; try { socket = new DatagramSocket(port); } catch (SocketException e) { @@ -45,6 +45,10 @@ public class BroadcastListener { return packet; } + public void interrupt() { + socket.close(); + } + public static void main(String[] args) { int port = Integer.parseInt(args[0]); BroadcastListener listener = new BroadcastListener(port); |