Skip to content

Commit

Permalink
Unnecessary Port Binding for ArtNet Sender cansik#26
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 94fd93b commit 97276f1
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 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,14 +95,22 @@ public void artNetPacketReceived(ArtNetPacket packet) {
}
});

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

isRunning = true;
} catch (SocketException | ArtNetException e) {
e.printStackTrace();
}
}

/**
* 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.
*/
Expand Down

0 comments on commit 97276f1

Please sign in to comment.