diff --git a/src/ch/epfl/lca/sc250/TCPClient.java b/src/ch/epfl/lca/sc250/TCPClient.java index 64a03b2..6af703b 100644 --- a/src/ch/epfl/lca/sc250/TCPClient.java +++ b/src/ch/epfl/lca/sc250/TCPClient.java @@ -48,16 +48,22 @@ try { String cmd = consoleReader.readLine(); - if ( cmd.trim().equals("Bye Bye") ) { - finished = true; - } + try { + if ( cmd.trim().equals("Bye Bye") ) { + finished = true; + } - write(cmd); - gui.appendText(cmd); - gui.appendText(read()); + write(cmd); + gui.appendText(cmd+"\n"); + gui.appendText(read()+"\n"); + } catch ( NullPointerException e ) { + System.err.println("NullPointerException"); + gui.appendText("NullPointerException\n"); + e.printStackTrace(); + } } catch ( IOException e ) { System.err.println("IOError"); - gui.appendText("IO-Error"); + gui.appendText("IO-Error\n"); e.printStackTrace(); } } @@ -76,11 +82,11 @@ sock = new Socket(targethost, targetport); } catch ( UnknownHostException uhe ) { System.out.println("Unknown host"); - gui.appendText("Unknown host"); + gui.appendText("Unknown host\n"); uhe.printStackTrace(); } catch ( IOException e ) { System.err.println("IOError"); - gui.appendText("IO-Error"); + gui.appendText("IO-Error\n"); e.printStackTrace(); } @@ -89,7 +95,7 @@ inr = new BufferedReader(new InputStreamReader(sock.getInputStream())); } catch ( IOException e ) { System.err.println("IOError"); - gui.appendText("IO-Error"); + gui.appendText("IO-Error\n"); e.printStackTrace(); } } @@ -98,7 +104,7 @@ write("Hello: " + name + "\n"); String t = read(); System.out.println(t); - gui.appendText(t); + gui.appendText(t+"\n"); } public void leave ( ) { @@ -106,11 +112,11 @@ sock.close(); } catch ( IOException e ) { System.err.println("IOError"); - gui.appendText("IO-Error"); + gui.appendText("IO-Error\n"); e.printStackTrace(); } System.out.println("Connection closed."); - gui.appendText("Connection closed."); + gui.appendText("Connection closed.\n"); } public void write ( String s ) { @@ -118,7 +124,7 @@ outs.writeBytes(s); } catch ( IOException e ) { System.err.println("IOError"); - gui.appendText("IO-Error"); + gui.appendText("IO-Error\n"); e.printStackTrace(); } } @@ -128,7 +134,7 @@ return inr.readLine(); } catch ( IOException e ) { System.err.println("IOError"); - gui.appendText("IO-Error"); + gui.appendText("IO-Error\n"); e.printStackTrace(); return ""; }