Skip to content
This repository has been archived by the owner on Oct 1, 2020. It is now read-only.

Commit

Permalink
Fix: Close socket on shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
trifel committed Feb 13, 2019
1 parent 8754d19 commit 8133ce2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/main/java/com/ictreport/ixi/api/Api.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ public void init() {
public void shutDown() {
receiver.shutDown();
sender.shutDown();
try {
this.socket.close();
} catch (Exception e) {
}
}

public Receiver getReceiver() {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/ictreport/ixi/api/Sender.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public void send(final Payload payload, String host, final int port) {
public synchronized void send(final Payload payload, final InetSocketAddress address) {
try {
final byte[] messageByteArray = Payload.serialize(payload).getBytes();
socket.send(new DatagramPacket(messageByteArray, messageByteArray.length, address));
if (socket != null && !socket.isClosed()) socket.send(new DatagramPacket(messageByteArray, messageByteArray.length, address));
} catch (final IOException | RuntimeException e) {
e.printStackTrace();
}
Expand Down

0 comments on commit 8133ce2

Please sign in to comment.