Fix bug with reuse of closed sockets
flavien's git/Projet_JAVA_P2P_STRI2A/pipeline/pr-master This commit looks good Details

pull/84/head
Louis Royer 4 years ago
parent 2cc2868450
commit 89a69c7e0c

@ -32,7 +32,7 @@ public class HostItem {
* @return TCP Socket * @return TCP Socket
*/ */
public Socket getTCPSocket() { public Socket getTCPSocket() {
if (tcpSocket == null) { if (tcpSocket == null || tcpSocket.isClosed()) {
try { try {
tcpSocket = new Socket(InetAddress.getByName(hostname), port); tcpSocket = new Socket(InetAddress.getByName(hostname), port);
} catch (SocketException e) { } catch (SocketException e) {
@ -56,7 +56,7 @@ public class HostItem {
* @throws IOException * @throws IOException
*/ */
public Socket tryGetTCPSocket() throws SocketException, UnknownHostException, IOException { public Socket tryGetTCPSocket() throws SocketException, UnknownHostException, IOException {
if (tcpSocket == null) { if (tcpSocket == null || tcpSocket.isClosed()) {
tcpSocket = new Socket(InetAddress.getByName(hostname), port); tcpSocket = new Socket(InetAddress.getByName(hostname), port);
} }
return tcpSocket; return tcpSocket;
@ -79,7 +79,7 @@ public class HostItem {
* return UDP Socket * return UDP Socket
*/ */
public DatagramSocket getUDPSocket() { public DatagramSocket getUDPSocket() {
if (udpSocket == null) { if (udpSocket == null || udpSocket.isClosed()) {
try { try {
udpSocket = new DatagramSocket(); udpSocket = new DatagramSocket();
udpSocket.connect(InetAddress.getByName(hostname), port); udpSocket.connect(InetAddress.getByName(hostname), port);

Loading…
Cancel
Save