diff options
author | Kjetil Ørbekk <kjetil.orbekk@gmail.com> | 2012-02-07 09:33:48 +0100 |
---|---|---|
committer | Kjetil Ørbekk <kjetil.orbekk@gmail.com> | 2012-02-07 09:33:48 +0100 |
commit | 523d8655d89d07724569dad790f8564ec623167d (patch) | |
tree | d6dce9a688bfd2eb638dfa245091e7e2cfbb5d61 /same/src/main/java/com | |
parent | 7e8f0f25129785068db661cab80cc13d658120a4 (diff) |
Add interrupt() support to BroadcastListener.
Diffstat (limited to 'same/src/main/java/com')
-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); |