Skip to content

Commit

Permalink
Removed duplication in InfrastructureInstance by adding sendPacket me…
Browse files Browse the repository at this point in the history
…thod
  • Loading branch information
paulbourelly999 committed Jul 27, 2023
1 parent 2f201f4 commit be88743
Showing 1 changed file with 8 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -187,12 +187,7 @@ public void bind() throws IOException {
* methods
*/
public void sendMsgs(byte[] data) throws IOException {
if (rxMsgsSocket == null) {
throw new IllegalStateException("Attempted to send data before opening socket");
}
DatagramPacket packet = new DatagramPacket(data, data.length, targetAddress, rxMessagePort);
rxMsgsSocket.send(packet);

sendPacket(data, rxMessagePort);
}

/**
Expand All @@ -201,20 +196,18 @@ public void sendMsgs(byte[] data) throws IOException {
* @throws IOException If there is an issue with the underlying socket object or methods
*/
public void sendTimeSyncMsgs(byte[] data) throws IOException {
if (rxMsgsSocket == null) {
throw new IllegalStateException("Attempted to send data before opening socket");
}

DatagramPacket packet = new DatagramPacket(data, data.length, targetAddress, timeSyncPort);
rxMsgsSocket.send(packet);

sendPacket(data, timeSyncPort);
}

public void sendInteraction(byte[] data) throws IOException {
if (rxMsgsSocket == null) {
sendPacket(data, simulatedInteractionPort);
}

public void sendPacket(byte[] data, int port) throws IOException {
if (rxMsgsSocket == null) {
throw new IllegalStateException("Attempted to send data before opening socket");
}
DatagramPacket packet = new DatagramPacket(data, data.length, targetAddress, simulatedInteractionPort);
DatagramPacket packet = new DatagramPacket(data, data.length, targetAddress, port);
rxMsgsSocket.send(packet);
}
}

0 comments on commit be88743

Please sign in to comment.