From 89a69c7e0c08d6add9570af5be3ffe2be945a910 Mon Sep 17 00:00:00 2001 From: Louis Royer Date: Mon, 30 Mar 2020 15:19:17 +0200 Subject: [PATCH] Fix bug with reuse of closed sockets --- src/tools/HostItem.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/tools/HostItem.java b/src/tools/HostItem.java index 3467a73..0ac3ae1 100644 --- a/src/tools/HostItem.java +++ b/src/tools/HostItem.java @@ -32,7 +32,7 @@ public class HostItem { * @return TCP Socket */ public Socket getTCPSocket() { - if (tcpSocket == null) { + if (tcpSocket == null || tcpSocket.isClosed()) { try { tcpSocket = new Socket(InetAddress.getByName(hostname), port); } catch (SocketException e) { @@ -56,7 +56,7 @@ public class HostItem { * @throws IOException */ public Socket tryGetTCPSocket() throws SocketException, UnknownHostException, IOException { - if (tcpSocket == null) { + if (tcpSocket == null || tcpSocket.isClosed()) { tcpSocket = new Socket(InetAddress.getByName(hostname), port); } return tcpSocket; @@ -79,7 +79,7 @@ public class HostItem { * return UDP Socket */ public DatagramSocket getUDPSocket() { - if (udpSocket == null) { + if (udpSocket == null || udpSocket.isClosed()) { try { udpSocket = new DatagramSocket(); udpSocket.connect(InetAddress.getByName(hostname), port);