From 054c22d5cfb02464adc28a9d3d4c387548f4ec89 Mon Sep 17 00:00:00 2001 From: ibuprofane Date: Fri, 31 Mar 2017 11:13:58 -0700 Subject: [PATCH] Updated BroadcastListener to set port for reuse The original code was impacting Android users. If multiple apps using this code were open then only the first app would be able to connect to the socket. The new code allows the socket to be shared. --- .../java/org/timothyb89/lifx/net/BroadcastListener.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/timothyb89/lifx/net/BroadcastListener.java b/src/main/java/org/timothyb89/lifx/net/BroadcastListener.java index 3981211..8164aaa 100644 --- a/src/main/java/org/timothyb89/lifx/net/BroadcastListener.java +++ b/src/main/java/org/timothyb89/lifx/net/BroadcastListener.java @@ -91,8 +91,10 @@ public void startListen(boolean daemon) throws IOException { } channel = DatagramChannel.open(); - channel.socket().bind(new InetSocketAddress(BROADCAST_PORT)); - channel.socket().setBroadcast(true); + DatagramSocket socket = channel.socket(); + socket.setReuseAddress(true); + socket.bind(new InetSocketAddress(BROADCAST_PORT)); + socket.setBroadcast(true); channel.configureBlocking(true); listenerThread = new Thread(listener, "lifx-udp-listen");