From 0cf1553f66c0222b25da92d02bbfd9c44399ff20 Mon Sep 17 00:00:00 2001 From: Marc Dimmerling Date: Thu, 8 Feb 2024 15:02:11 +0100 Subject: [PATCH] if connectionToServer --- src/main/java/ChatClient.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/main/java/ChatClient.java b/src/main/java/ChatClient.java index 2dfd152..b038e1a 100644 --- a/src/main/java/ChatClient.java +++ b/src/main/java/ChatClient.java @@ -62,12 +62,16 @@ public class ChatClient extends JFrame implements KeyListener { JOptionPane.showMessageDialog(null, "Verbindung zum Server \"" + address + "\" fehlgeschlagen."); } finally { - try { + if (connectionToServer != null) { + try { connectionToServer.close(); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } + } + + catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } // fromServerReader.close(); (warten auf ServerReader) // toServerWriter.close(); (warten auf ServerWriter) }