summaryrefslogtreecommitdiff
path: root/jsonrpc/src/main/java/com/orbekk
diff options
context:
space:
mode:
Diffstat (limited to 'jsonrpc/src/main/java/com/orbekk')
-rw-r--r--jsonrpc/src/main/java/com/orbekk/net/BroadcastListener.java22
1 files changed, 13 insertions, 9 deletions
diff --git a/jsonrpc/src/main/java/com/orbekk/net/BroadcastListener.java b/jsonrpc/src/main/java/com/orbekk/net/BroadcastListener.java
index 50cdbc7..c0b66e0 100644
--- a/jsonrpc/src/main/java/com/orbekk/net/BroadcastListener.java
+++ b/jsonrpc/src/main/java/com/orbekk/net/BroadcastListener.java
@@ -5,40 +5,44 @@ import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.SocketException;
-import org.apache.log4j.Logger;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public class BroadcastListener {
private int port;
- private Logger logger = Logger.getLogger(getClass());
+ private Logger logger = LoggerFactory.getLogger(getClass());
public BroadcastListener(int port) {
this.port = port;
}
- public boolean listen() {
- logger.info("Waiting for broadcast on port " + port);
+ public DatagramPacket listen() {
+ logger.debug("Waiting for broadcast on port " + port);
DatagramSocket socket;
try {
socket = new DatagramSocket(port);
} catch (SocketException e) {
logger.warn("Failed to create socket.", e.fillInStackTrace());
- return true;
+ return null;
}
try {
socket.setBroadcast(true);
} catch (SocketException e) {
- logger.warn(e.fillInStackTrace());
+ logger.warn("Exception: {}", e);
}
byte[] buffer = new byte[2048];
DatagramPacket packet = new DatagramPacket(buffer, buffer.length);
try {
socket.receive(packet);
} catch (IOException e) {
- logger.warn(e.fillInStackTrace());
+ logger.warn("Exception when listening for broadcast: {}", e);
+ return null;
}
- logger.info("Received broadcast from " + packet.getAddress() +
+
+ String address = packet.getAddress().getHostAddress();
+ logger.debug("Received broadcast from " + address +
": " + new String(packet.getData()));
- return true;
+ return packet;
}
public static void main(String[] args) {