Skip to content

Commit

Permalink
Fix Unnecessary Port Binding for ArtNet Sender
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tylerstraub committed May 31, 2024
1 parent 81dd42f commit 43f696c
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/main/java/ch/bildspur/artnet/ArtNetClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand All @@ -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();
}
Expand All @@ -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;

Expand All @@ -87,7 +95,7 @@ public void artNetPacketReceived(ArtNetPacket packet) {
}
});

server.start(networkInterfaceAddress);
server.start(networkInterfaceAddress, isReceiver);

isRunning = true;
} catch (SocketException | ArtNetException e) {
Expand Down

0 comments on commit 43f696c

Please sign in to comment.