From 81dd42fc0da965930d079fb371f73f183bb19dcf Mon Sep 17 00:00:00 2001 From: Tyler Straub Date: Thu, 30 May 2024 21:50:15 -0700 Subject: [PATCH 1/7] Fix Unnecessary Port Binding for ArtNet Sender #26 Modify the artnet4j library to avoid static binding its port when acting solely as a Sender. Instead, it should use an ephemeral port for sending data. --- .../java/ch/bildspur/artnet/ArtNetServer.java | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/main/java/ch/bildspur/artnet/ArtNetServer.java b/src/main/java/ch/bildspur/artnet/ArtNetServer.java index c198550..a0d4ec9 100644 --- a/src/main/java/ch/bildspur/artnet/ArtNetServer.java +++ b/src/main/java/ch/bildspur/artnet/ArtNetServer.java @@ -158,10 +158,14 @@ private void setBufferSize(int size) { } public void start() throws SocketException, ArtNetException { - start(null); + start(null, true); } public void start(InetAddress networkAddress) throws SocketException, ArtNetException { + start(networkAddress, true); + } + + public void start(InetAddress networkAddress, boolean isReceiver) throws SocketException, ArtNetException { if (broadCastAddress == null) { setBroadcastAddress(DEFAULT_BROADCAST_IP); } @@ -170,12 +174,16 @@ public void start(InetAddress networkAddress) throws SocketException, ArtNetExce socket.setReuseAddress(true); socket.setBroadcast(true); - if (networkAddress == null) - networkAddress = socket.getLocalAddress(); + if (isReceiver) { + if (networkAddress == null) + networkAddress = socket.getLocalAddress(); - socket.bind(new InetSocketAddress(networkAddress, port)); + socket.bind(new InetSocketAddress(networkAddress, port)); + logger.info("Art-Net server started at: " + networkAddress.getHostAddress() + ":" + port); + } else { + logger.info("Art-Net server started as sender using ephemeral port."); + } - logger.info("Art-Net server started at: " + networkAddress.getHostAddress() + ":" + port); for (ArtNetServerListener l : listeners) { l.artNetServerStarted(this); } From 43f696cf2adfa269a4019c03961730e4b378d874 Mon Sep 17 00:00:00 2001 From: Tyler Straub Date: Thu, 30 May 2024 22:33:15 -0700 Subject: [PATCH 2/7] Fix Unnecessary Port Binding for ArtNet Sender Modify the artnet4j library to avoid static binding its port when acting solely as a Sender. Instead, it should use an ephemeral port for sending data. --- .../java/ch/bildspur/artnet/ArtNetClient.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/main/java/ch/bildspur/artnet/ArtNetClient.java b/src/main/java/ch/bildspur/artnet/ArtNetClient.java index 2019324..7b572a6 100644 --- a/src/main/java/ch/bildspur/artnet/ArtNetClient.java +++ b/src/main/java/ch/bildspur/artnet/ArtNetClient.java @@ -49,8 +49,7 @@ public ArtNetClient(ArtNetBuffer inputBuffer, int serverPort, int clientPort) { * Start client with default arguments (listen on broadcast). */ public void start() { - // use default network interface - this.start((InetAddress)null); + this.start(null, inputBuffer != null); } /** @@ -60,7 +59,7 @@ public void start() { public void start(String networkInterfaceAddress) { try { - this.start(InetAddress.getByName(networkInterfaceAddress)); + this.start(InetAddress.getByName(networkInterfaceAddress), inputBuffer != null); } catch (UnknownHostException e) { e.printStackTrace(); } @@ -71,6 +70,15 @@ public void start(String networkInterfaceAddress) * @param networkInterfaceAddress Network interface address to listen to. */ public void start(InetAddress networkInterfaceAddress) { + this.start(networkInterfaceAddress, inputBuffer != null); + } + + /** + * Start client with specific network interface address and receiver mode. + * @param networkInterfaceAddress Network interface address to listen to. + * @param isReceiver If true, the client will bind to the specified port to receive data. + */ + public void start(InetAddress networkInterfaceAddress, boolean isReceiver) { if (isRunning) return; @@ -87,7 +95,7 @@ public void artNetPacketReceived(ArtNetPacket packet) { } }); - server.start(networkInterfaceAddress); + server.start(networkInterfaceAddress, isReceiver); isRunning = true; } catch (SocketException | ArtNetException e) { From 94fd93be79f6511d850289dd0cbe1a27b88cd93b Mon Sep 17 00:00:00 2001 From: Tyler Straub Date: Thu, 30 May 2024 22:47:39 -0700 Subject: [PATCH 3/7] Revert "Fix Unnecessary Port Binding for ArtNet Sender" This reverts commit 43f696cf2adfa269a4019c03961730e4b378d874. --- .../java/ch/bildspur/artnet/ArtNetClient.java | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/src/main/java/ch/bildspur/artnet/ArtNetClient.java b/src/main/java/ch/bildspur/artnet/ArtNetClient.java index 7b572a6..2019324 100644 --- a/src/main/java/ch/bildspur/artnet/ArtNetClient.java +++ b/src/main/java/ch/bildspur/artnet/ArtNetClient.java @@ -49,7 +49,8 @@ public ArtNetClient(ArtNetBuffer inputBuffer, int serverPort, int clientPort) { * Start client with default arguments (listen on broadcast). */ public void start() { - this.start(null, inputBuffer != null); + // use default network interface + this.start((InetAddress)null); } /** @@ -59,7 +60,7 @@ public void start() { public void start(String networkInterfaceAddress) { try { - this.start(InetAddress.getByName(networkInterfaceAddress), inputBuffer != null); + this.start(InetAddress.getByName(networkInterfaceAddress)); } catch (UnknownHostException e) { e.printStackTrace(); } @@ -70,15 +71,6 @@ public void start(String networkInterfaceAddress) * @param networkInterfaceAddress Network interface address to listen to. */ public void start(InetAddress networkInterfaceAddress) { - this.start(networkInterfaceAddress, inputBuffer != null); - } - - /** - * Start client with specific network interface address and receiver mode. - * @param networkInterfaceAddress Network interface address to listen to. - * @param isReceiver If true, the client will bind to the specified port to receive data. - */ - public void start(InetAddress networkInterfaceAddress, boolean isReceiver) { if (isRunning) return; @@ -95,7 +87,7 @@ public void artNetPacketReceived(ArtNetPacket packet) { } }); - server.start(networkInterfaceAddress, isReceiver); + server.start(networkInterfaceAddress); isRunning = true; } catch (SocketException | ArtNetException e) { From 97276f186b157e1550c6516dfd133b6bb4932c59 Mon Sep 17 00:00:00 2001 From: Tyler Straub Date: Thu, 30 May 2024 22:50:53 -0700 Subject: [PATCH 4/7] Unnecessary Port Binding for ArtNet Sender #26 Modify the artnet4j library to avoid static binding its port when acting solely as a Sender. Instead, it should use an ephemeral port for sending data. --- .../java/ch/bildspur/artnet/ArtNetClient.java | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/main/java/ch/bildspur/artnet/ArtNetClient.java b/src/main/java/ch/bildspur/artnet/ArtNetClient.java index 2019324..f7024b1 100644 --- a/src/main/java/ch/bildspur/artnet/ArtNetClient.java +++ b/src/main/java/ch/bildspur/artnet/ArtNetClient.java @@ -49,8 +49,7 @@ public ArtNetClient(ArtNetBuffer inputBuffer, int serverPort, int clientPort) { * Start client with default arguments (listen on broadcast). */ public void start() { - // use default network interface - this.start((InetAddress)null); + this.start(null, inputBuffer != null); } /** @@ -60,7 +59,7 @@ public void start() { public void start(String networkInterfaceAddress) { try { - this.start(InetAddress.getByName(networkInterfaceAddress)); + this.start(InetAddress.getByName(networkInterfaceAddress), inputBuffer != null); } catch (UnknownHostException e) { e.printStackTrace(); } @@ -71,6 +70,15 @@ public void start(String networkInterfaceAddress) * @param networkInterfaceAddress Network interface address to listen to. */ public void start(InetAddress networkInterfaceAddress) { + this.start(networkInterfaceAddress, inputBuffer != null); + } + + /** + * Start client with specific network interface address and receiver mode. + * @param networkInterfaceAddress Network interface address to listen to. + * @param isReceiver If true, the client will bind to the specified port to receive data. + */ + public void start(InetAddress networkInterfaceAddress, boolean isReceiver) { if (isRunning) return; @@ -87,7 +95,7 @@ public void artNetPacketReceived(ArtNetPacket packet) { } }); - server.start(networkInterfaceAddress); + server.start(networkInterfaceAddress, isReceiver); isRunning = true; } catch (SocketException | ArtNetException e) { @@ -95,6 +103,14 @@ public void artNetPacketReceived(ArtNetPacket packet) { } } + /** + * Start client with receiver mode. + * @param isReceiver If true, the client will bind to the specified port to receive data. + */ + public void start(boolean isReceiver) { + this.start((InetAddress) null, isReceiver); + } + /** * Stops the client and udp server. */ From 90c78e9ba21d82a28d55aa9b18d6068f4bb10d73 Mon Sep 17 00:00:00 2001 From: Tyler Straub Date: Fri, 31 May 2024 00:35:02 -0700 Subject: [PATCH 5/7] maintain backward compatibility --- src/main/java/ch/bildspur/artnet/ArtNetClient.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/ch/bildspur/artnet/ArtNetClient.java b/src/main/java/ch/bildspur/artnet/ArtNetClient.java index f7024b1..2765800 100644 --- a/src/main/java/ch/bildspur/artnet/ArtNetClient.java +++ b/src/main/java/ch/bildspur/artnet/ArtNetClient.java @@ -49,7 +49,7 @@ public ArtNetClient(ArtNetBuffer inputBuffer, int serverPort, int clientPort) { * Start client with default arguments (listen on broadcast). */ public void start() { - this.start(null, inputBuffer != null); + this.start(null, true); // default to static binding (receiver mode) } /** From f993fb3890a7f6a99cbc827085fda9e686048fc5 Mon Sep 17 00:00:00 2001 From: Tyler Straub Date: Fri, 31 May 2024 00:43:55 -0700 Subject: [PATCH 6/7] adjust for startup log parity --- src/main/java/ch/bildspur/artnet/ArtNetServer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/ch/bildspur/artnet/ArtNetServer.java b/src/main/java/ch/bildspur/artnet/ArtNetServer.java index a0d4ec9..c5ff5c1 100644 --- a/src/main/java/ch/bildspur/artnet/ArtNetServer.java +++ b/src/main/java/ch/bildspur/artnet/ArtNetServer.java @@ -181,7 +181,7 @@ public void start(InetAddress networkAddress, boolean isReceiver) throws SocketE socket.bind(new InetSocketAddress(networkAddress, port)); logger.info("Art-Net server started at: " + networkAddress.getHostAddress() + ":" + port); } else { - logger.info("Art-Net server started as sender using ephemeral port."); + logger.info("Art-Net server started at: " + networkAddress.getHostAddress() + ":" + port + " (ephemeral mode)"); } for (ArtNetServerListener l : listeners) { From bc1f32cc4eb79e7c64099ceca6d5ba12c07bf216 Mon Sep 17 00:00:00 2001 From: Tyler Straub Date: Fri, 31 May 2024 00:46:04 -0700 Subject: [PATCH 7/7] Revert "adjust for startup log parity" This reverts commit f993fb3890a7f6a99cbc827085fda9e686048fc5. --- src/main/java/ch/bildspur/artnet/ArtNetServer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/ch/bildspur/artnet/ArtNetServer.java b/src/main/java/ch/bildspur/artnet/ArtNetServer.java index c5ff5c1..a0d4ec9 100644 --- a/src/main/java/ch/bildspur/artnet/ArtNetServer.java +++ b/src/main/java/ch/bildspur/artnet/ArtNetServer.java @@ -181,7 +181,7 @@ public void start(InetAddress networkAddress, boolean isReceiver) throws SocketE socket.bind(new InetSocketAddress(networkAddress, port)); logger.info("Art-Net server started at: " + networkAddress.getHostAddress() + ":" + port); } else { - logger.info("Art-Net server started at: " + networkAddress.getHostAddress() + ":" + port + " (ephemeral mode)"); + logger.info("Art-Net server started as sender using ephemeral port."); } for (ArtNetServerListener l : listeners) {