From fb8026ee003c1597893b6a511974a5b91c99bfca Mon Sep 17 00:00:00 2001 From: Darien Arthur-Gocken <233949874+DarienArthur-Gocken@users.noreply.github.com> Date: Thu, 4 Dec 2025 09:05:30 -0800 Subject: [PATCH 01/21] initial parseargs work --- src/ChatterboxClient.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/ChatterboxClient.java b/src/ChatterboxClient.java index 9f80fc0..874deb9 100644 --- a/src/ChatterboxClient.java +++ b/src/ChatterboxClient.java @@ -125,9 +125,18 @@ public static void main(String[] args) { * @throws IllegalArgumentException on any bad/missing input */ public static ChatterboxOptions parseArgs(String[] args) throws IllegalArgumentException { - // TODO: read args in the required order and return new ChatterboxOptions(host, port, username, password) - // Remove this exception - throw new UnsupportedOperationException("Argument parsing not yet implemented. Implement parseArgs and remove this exception"); + if(args.length != 4) { + throw new IllegalArgumentException("parseArgs must be passed exactly four arguments!"); + } + String host = args[0]; + int port = Integer.parseInt(args[1]); + String username = args[2]; + String password = args[3]; + + if(port < 1 || port > 65535) { + throw new IllegalArgumentException("Port was not passed in as a int between 1 & 65535."); + } + } /** From e4a8f65b15c22553e41dfdc24dfefe3196df6c70 Mon Sep 17 00:00:00 2001 From: Darien Arthur-Gocken <233949874+DarienArthur-Gocken@users.noreply.github.com> Date: Thu, 4 Dec 2025 11:24:21 -0800 Subject: [PATCH 02/21] options --- src/ChatterboxClient.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/ChatterboxClient.java b/src/ChatterboxClient.java index 874deb9..2281850 100644 --- a/src/ChatterboxClient.java +++ b/src/ChatterboxClient.java @@ -134,9 +134,13 @@ public static ChatterboxOptions parseArgs(String[] args) throws IllegalArgumentE String password = args[3]; if(port < 1 || port > 65535) { - throw new IllegalArgumentException("Port was not passed in as a int between 1 & 65535."); + throw new IllegalArgumentException("Port was not passed in as a number between 1 & 65535."); } + ChatterboxOptions options = new ChatterboxOptions(host, port, username, password); + + return options; + } /** From f137fb324777ac14c1eb32901345bf2d66480363 Mon Sep 17 00:00:00 2001 From: Darien Arthur-Gocken <233949874+DarienArthur-Gocken@users.noreply.github.com> Date: Thu, 4 Dec 2025 11:29:10 -0800 Subject: [PATCH 03/21] added constructor copys for options --- src/ChatterboxClient.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/ChatterboxClient.java b/src/ChatterboxClient.java index 2281850..f3b4767 100644 --- a/src/ChatterboxClient.java +++ b/src/ChatterboxClient.java @@ -159,7 +159,10 @@ public ChatterboxClient(ChatterboxOptions options, InputStream userInput, Output this.userInput = new Scanner(userInput, StandardCharsets.UTF_8); this.userOutput = userOutput; - throw new UnsupportedOperationException("Constructor not yet implemented. Implement ChatterboxClient constructor and remove this exception"); + this.host = options.getHost(); + this.port = options.getPort(); + this.username = options.getUsername(); + this.password = options.getPassword(); // TODO: copy options.getHost(), getPort(), getUsername(), getPassword() into fields } From 8b47a7e5ced9268ae1dbdea29d31b31a2c72347d Mon Sep 17 00:00:00 2001 From: Darien Arthur-Gocken <233949874+DarienArthur-Gocken@users.noreply.github.com> Date: Thu, 4 Dec 2025 11:33:33 -0800 Subject: [PATCH 04/21] server reader/writer --- src/ChatterboxClient.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/ChatterboxClient.java b/src/ChatterboxClient.java index f3b4767..0971a5d 100644 --- a/src/ChatterboxClient.java +++ b/src/ChatterboxClient.java @@ -2,7 +2,10 @@ import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStream; +import java.io.InputStreamReader; import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.net.Socket; import java.nio.charset.StandardCharsets; import java.util.Scanner; @@ -180,7 +183,15 @@ public ChatterboxClient(ChatterboxOptions options, InputStream userInput, Output * @throws IOException if the socket cannot be opened */ public void connect() throws IOException { - throw new UnsupportedOperationException("Connect not yet implemented. Implement connect() and remove this exception!"); + try(Socket socket = new Socket(getHost(), getPort())) { + InputStream inputStream = socket.getInputStream(); + InputStreamReader inputStreamReader = new InputStreamReader(inputStream, java.nio.charset.StandardCharsets.UTF_8); + serverReader = new BufferedReader(inputStreamReader); + + OutputStream outputStream = socket.getOutputStream(); + OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputStream, java.nio.charset.StandardCharsets.UTF_8); + serverWriter = new BufferedWriter(outputStreamWriter); + } // Make sure to have this.serverReader and this.serverWriter set by the end of this method! // hint: get the streams from the sockets, use those to create the InputStreamReader/OutputStreamWriter and the BufferedReader/BufferedWriter From 3d0eee7cae0cfa4f8822c208b6c682241a24b5d6 Mon Sep 17 00:00:00 2001 From: Darien Arthur-Gocken <233949874+DarienArthur-Gocken@users.noreply.github.com> Date: Thu, 4 Dec 2025 11:34:05 -0800 Subject: [PATCH 05/21] this. just incase --- src/ChatterboxClient.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ChatterboxClient.java b/src/ChatterboxClient.java index 0971a5d..9ae09c6 100644 --- a/src/ChatterboxClient.java +++ b/src/ChatterboxClient.java @@ -186,11 +186,11 @@ public void connect() throws IOException { try(Socket socket = new Socket(getHost(), getPort())) { InputStream inputStream = socket.getInputStream(); InputStreamReader inputStreamReader = new InputStreamReader(inputStream, java.nio.charset.StandardCharsets.UTF_8); - serverReader = new BufferedReader(inputStreamReader); + this.serverReader = new BufferedReader(inputStreamReader); OutputStream outputStream = socket.getOutputStream(); OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputStream, java.nio.charset.StandardCharsets.UTF_8); - serverWriter = new BufferedWriter(outputStreamWriter); + this.serverWriter = new BufferedWriter(outputStreamWriter); } // Make sure to have this.serverReader and this.serverWriter set by the end of this method! From c0951f27a7e2aaefc96f1dac0d45739bc34a8688 Mon Sep 17 00:00:00 2001 From: Darien Arthur-Gocken <233949874+DarienArthur-Gocken@users.noreply.github.com> Date: Thu, 4 Dec 2025 11:35:17 -0800 Subject: [PATCH 06/21] catch exception --- src/ChatterboxClient.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/ChatterboxClient.java b/src/ChatterboxClient.java index 9ae09c6..775157c 100644 --- a/src/ChatterboxClient.java +++ b/src/ChatterboxClient.java @@ -191,6 +191,9 @@ public void connect() throws IOException { OutputStream outputStream = socket.getOutputStream(); OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputStream, java.nio.charset.StandardCharsets.UTF_8); this.serverWriter = new BufferedWriter(outputStreamWriter); + } catch (IOException e) { + System.out.println("Socket failed to be constructed."); + return; } // Make sure to have this.serverReader and this.serverWriter set by the end of this method! From da7b5eba8f06bdb66aeecf44f0868f168f91185a Mon Sep 17 00:00:00 2001 From: Darien Arthur-Gocken <233949874+DarienArthur-Gocken@users.noreply.github.com> Date: Thu, 4 Dec 2025 11:46:35 -0800 Subject: [PATCH 07/21] proper args used --- src/ChatterboxClient.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/ChatterboxClient.java b/src/ChatterboxClient.java index 775157c..508fe4b 100644 --- a/src/ChatterboxClient.java +++ b/src/ChatterboxClient.java @@ -166,7 +166,6 @@ public ChatterboxClient(ChatterboxOptions options, InputStream userInput, Output this.port = options.getPort(); this.username = options.getUsername(); this.password = options.getPassword(); - // TODO: copy options.getHost(), getPort(), getUsername(), getPassword() into fields } /** @@ -188,8 +187,8 @@ public void connect() throws IOException { InputStreamReader inputStreamReader = new InputStreamReader(inputStream, java.nio.charset.StandardCharsets.UTF_8); this.serverReader = new BufferedReader(inputStreamReader); - OutputStream outputStream = socket.getOutputStream(); - OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputStream, java.nio.charset.StandardCharsets.UTF_8); + this.userOutput = socket.getOutputStream(); + OutputStreamWriter outputStreamWriter = new OutputStreamWriter(this.userOutput, java.nio.charset.StandardCharsets.UTF_8); this.serverWriter = new BufferedWriter(outputStreamWriter); } catch (IOException e) { System.out.println("Socket failed to be constructed."); From 904e904ad7b683fc8e8e1dbe1c7696cca6eb0c35 Mon Sep 17 00:00:00 2001 From: Darien Arthur-Gocken <233949874+DarienArthur-Gocken@users.noreply.github.com> Date: Thu, 4 Dec 2025 12:00:11 -0800 Subject: [PATCH 08/21] initial auth --- src/ChatterboxClient.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/ChatterboxClient.java b/src/ChatterboxClient.java index 508fe4b..e414205 100644 --- a/src/ChatterboxClient.java +++ b/src/ChatterboxClient.java @@ -194,9 +194,6 @@ public void connect() throws IOException { System.out.println("Socket failed to be constructed."); return; } - - // Make sure to have this.serverReader and this.serverWriter set by the end of this method! - // hint: get the streams from the sockets, use those to create the InputStreamReader/OutputStreamWriter and the BufferedReader/BufferedWriter } /** @@ -220,9 +217,14 @@ public void connect() throws IOException { * @throws IllegalArgumentException for bad credentials / server rejection */ public void authenticate() throws IOException, IllegalArgumentException { - throw new UnsupportedOperationException("Authenticate not yet implemented. Implement authenticate() and remove this exception!"); - // Hint: use the username/password instance variables, DO NOT READ FROM userInput - // send messages using serverWriter (don't forget to flush!) + String initialPrompt = serverReader.readLine(); + while(initialPrompt != null && initialPrompt.length() > 0) { + userOutput.write(initialPrompt.getBytes()); + initialPrompt = serverReader.readLine(); + } + + serverWriter.write(username + " " + password); + serverWriter.flush(); } /** From 343292f22863387f2408b20a52df331ff7ee875b Mon Sep 17 00:00:00 2001 From: Darien Arthur-Gocken <233949874+DarienArthur-Gocken@users.noreply.github.com> Date: Thu, 4 Dec 2025 12:10:42 -0800 Subject: [PATCH 09/21] error handling --- src/ChatterboxClient.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/ChatterboxClient.java b/src/ChatterboxClient.java index e414205..7bc9628 100644 --- a/src/ChatterboxClient.java +++ b/src/ChatterboxClient.java @@ -225,6 +225,16 @@ public void authenticate() throws IOException, IllegalArgumentException { serverWriter.write(username + " " + password); serverWriter.flush(); + + String response = serverReader.readLine(); + if(response == null) { + throw new IOException("Server didn't reply."); + } + + String errorCatch = response.toLowerCase(); + if(errorCatch.contains("error")) { + throw new IllegalArgumentException(response); + } } /** From 9b44aca5fa4e8c1809aa5f13a4d5863241641c65 Mon Sep 17 00:00:00 2001 From: Darien Arthur-Gocken <233949874+DarienArthur-Gocken@users.noreply.github.com> Date: Thu, 4 Dec 2025 12:13:29 -0800 Subject: [PATCH 10/21] substring --- src/ChatterboxClient.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/ChatterboxClient.java b/src/ChatterboxClient.java index 7bc9628..94843f7 100644 --- a/src/ChatterboxClient.java +++ b/src/ChatterboxClient.java @@ -231,10 +231,12 @@ public void authenticate() throws IOException, IllegalArgumentException { throw new IOException("Server didn't reply."); } - String errorCatch = response.toLowerCase(); + String errorCatch = response.toLowerCase().substring(0, 4); if(errorCatch.contains("error")) { throw new IllegalArgumentException(response); } + + } /** From e584c11a6d3d2efeb87fb1a466b1348c50e2f7dc Mon Sep 17 00:00:00 2001 From: Darien Arthur-Gocken <233949874+DarienArthur-Gocken@users.noreply.github.com> Date: Thu, 4 Dec 2025 12:20:26 -0800 Subject: [PATCH 11/21] auth work --- src/ChatterboxClient.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/ChatterboxClient.java b/src/ChatterboxClient.java index 94843f7..377d3c5 100644 --- a/src/ChatterboxClient.java +++ b/src/ChatterboxClient.java @@ -220,6 +220,7 @@ public void authenticate() throws IOException, IllegalArgumentException { String initialPrompt = serverReader.readLine(); while(initialPrompt != null && initialPrompt.length() > 0) { userOutput.write(initialPrompt.getBytes()); + userOutput.flush(); initialPrompt = serverReader.readLine(); } @@ -236,6 +237,13 @@ public void authenticate() throws IOException, IllegalArgumentException { throw new IllegalArgumentException(response); } + userOutput.write(response.getBytes()); + userOutput.flush(); + + while ((response = serverReader.readLine()) != null && response.length() > 0) { + userOutput.write((response + "\n").getBytes()); + userOutput.flush(); + } } From a26c6178c7c34499ff96c18c03d88805c141b1ed Mon Sep 17 00:00:00 2001 From: Darien Arthur-Gocken <233949874+DarienArthur-Gocken@users.noreply.github.com> Date: Thu, 4 Dec 2025 12:24:07 -0800 Subject: [PATCH 12/21] new line --- src/ChatterboxClient.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ChatterboxClient.java b/src/ChatterboxClient.java index 377d3c5..ef1d180 100644 --- a/src/ChatterboxClient.java +++ b/src/ChatterboxClient.java @@ -219,12 +219,12 @@ public void connect() throws IOException { public void authenticate() throws IOException, IllegalArgumentException { String initialPrompt = serverReader.readLine(); while(initialPrompt != null && initialPrompt.length() > 0) { - userOutput.write(initialPrompt.getBytes()); + userOutput.write((initialPrompt + "\n").getBytes()); userOutput.flush(); initialPrompt = serverReader.readLine(); } - serverWriter.write(username + " " + password); + serverWriter.write(username + " " + password + "\n"); serverWriter.flush(); String response = serverReader.readLine(); From 7dcb4fbb2c9c63823b0845f67783222a1d315e8e Mon Sep 17 00:00:00 2001 From: Darien Arthur-Gocken <233949874+DarienArthur-Gocken@users.noreply.github.com> Date: Fri, 5 Dec 2025 08:34:07 -0800 Subject: [PATCH 13/21] trying to get things to work --- src/ChatterboxClient.java | 39 ++++++++++++++++----------------------- 1 file changed, 16 insertions(+), 23 deletions(-) diff --git a/src/ChatterboxClient.java b/src/ChatterboxClient.java index ef1d180..f93ff48 100644 --- a/src/ChatterboxClient.java +++ b/src/ChatterboxClient.java @@ -182,18 +182,14 @@ public ChatterboxClient(ChatterboxOptions options, InputStream userInput, Output * @throws IOException if the socket cannot be opened */ public void connect() throws IOException { - try(Socket socket = new Socket(getHost(), getPort())) { - InputStream inputStream = socket.getInputStream(); - InputStreamReader inputStreamReader = new InputStreamReader(inputStream, java.nio.charset.StandardCharsets.UTF_8); - this.serverReader = new BufferedReader(inputStreamReader); - - this.userOutput = socket.getOutputStream(); - OutputStreamWriter outputStreamWriter = new OutputStreamWriter(this.userOutput, java.nio.charset.StandardCharsets.UTF_8); - this.serverWriter = new BufferedWriter(outputStreamWriter); - } catch (IOException e) { - System.out.println("Socket failed to be constructed."); - return; - } + Socket socket = new Socket(getHost(), getPort()); + InputStream inputStream = socket.getInputStream(); + InputStreamReader inputStreamReader = new InputStreamReader(inputStream); + this.serverReader = new BufferedReader(inputStreamReader); + + OutputStream outputStream = socket.getOutputStream(); + OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputStream); + this.serverWriter = new BufferedWriter(outputStreamWriter); } /** @@ -218,22 +214,19 @@ public void connect() throws IOException { */ public void authenticate() throws IOException, IllegalArgumentException { String initialPrompt = serverReader.readLine(); - while(initialPrompt != null && initialPrompt.length() > 0) { - userOutput.write((initialPrompt + "\n").getBytes()); - userOutput.flush(); - initialPrompt = serverReader.readLine(); - } - - serverWriter.write(username + " " + password + "\n"); - serverWriter.flush(); + userOutput.write((initialPrompt).getBytes()); + userOutput.flush(); + + this.serverWriter.write(this.username + " " + this.password); + this.serverWriter.flush(); String response = serverReader.readLine(); if(response == null) { throw new IOException("Server didn't reply."); } - String errorCatch = response.toLowerCase().substring(0, 4); - if(errorCatch.contains("error")) { + String errorCatch = response.toLowerCase(); + if (errorCatch.startsWith("error")) { throw new IllegalArgumentException(response); } @@ -241,7 +234,7 @@ public void authenticate() throws IOException, IllegalArgumentException { userOutput.flush(); while ((response = serverReader.readLine()) != null && response.length() > 0) { - userOutput.write((response + "\n").getBytes()); + userOutput.write(response.getBytes()); userOutput.flush(); } From dce36ec480187deca5ba11980c5347b328e2ed58 Mon Sep 17 00:00:00 2001 From: Darien Arthur-Gocken <233949874+DarienArthur-Gocken@users.noreply.github.com> Date: Fri, 5 Dec 2025 08:39:01 -0800 Subject: [PATCH 14/21] auth working --- src/ChatterboxClient.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/ChatterboxClient.java b/src/ChatterboxClient.java index f93ff48..0a17b01 100644 --- a/src/ChatterboxClient.java +++ b/src/ChatterboxClient.java @@ -217,10 +217,11 @@ public void authenticate() throws IOException, IllegalArgumentException { userOutput.write((initialPrompt).getBytes()); userOutput.flush(); - this.serverWriter.write(this.username + " " + this.password); + this.serverWriter.write(this.username + " " + this.password + "\n"); this.serverWriter.flush(); String response = serverReader.readLine(); + if(response == null) { throw new IOException("Server didn't reply."); } From 239cd9a31bcd30697d854bd9c4390c04f41637af Mon Sep 17 00:00:00 2001 From: Darien Arthur-Gocken <233949874+DarienArthur-Gocken@users.noreply.github.com> Date: Fri, 5 Dec 2025 08:52:49 -0800 Subject: [PATCH 15/21] streamlining + handler functions --- src/ChatterboxClient.java | 43 ++++++++++++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 10 deletions(-) diff --git a/src/ChatterboxClient.java b/src/ChatterboxClient.java index 0a17b01..3a5d3ac 100644 --- a/src/ChatterboxClient.java +++ b/src/ChatterboxClient.java @@ -9,6 +9,8 @@ import java.nio.charset.StandardCharsets; import java.util.Scanner; +import javax.imageio.IIOException; + /** * A simple command-line chat client for the Chatterbox server. * @@ -214,8 +216,7 @@ public void connect() throws IOException { */ public void authenticate() throws IOException, IllegalArgumentException { String initialPrompt = serverReader.readLine(); - userOutput.write((initialPrompt).getBytes()); - userOutput.flush(); + printToUser(initialPrompt); this.serverWriter.write(this.username + " " + this.password + "\n"); this.serverWriter.flush(); @@ -231,12 +232,10 @@ public void authenticate() throws IOException, IllegalArgumentException { throw new IllegalArgumentException(response); } - userOutput.write(response.getBytes()); - userOutput.flush(); + printToUser(response); while ((response = serverReader.readLine()) != null && response.length() > 0) { - userOutput.write(response.getBytes()); - userOutput.flush(); + printToUser(response); } } @@ -253,8 +252,8 @@ public void authenticate() throws IOException, IllegalArgumentException { * * @throws IOException */ - public void streamChat() throws IOException { - throw new UnsupportedOperationException("Chat streaming not yet implemented. Implement streamChat() and remove this exception!"); + public void streamChat() throws IOException { + printIncomingChats(); } /** @@ -272,8 +271,20 @@ public void streamChat() throws IOException { * print a message to userOutput and exit. */ public void printIncomingChats() { - // Listen on serverReader - // Write to userOutput, NOT System.out + try { + String incoming; + while((incoming = serverReader.readLine()) != null) { + printToUser(incoming); + } + + printToUser("Disconnected from Server."); + System.exit(0); + } catch(IOException i) { + try { + printToUser("Connection failed."); + } catch(IOException e) {} + System.exit(0); + } } /** @@ -294,6 +305,18 @@ public void sendOutgoingChats() { // write to serverOutput } + public void printToUser(String message) throws IOException { + try { + this.userOutput.write((message + "\n").getBytes()); + this.userOutput.flush(); + } catch(IOException e) { + } + } + + public void writeToServer(String message) throws IOException { + + } + public String getHost() { return host; } From 782ccdfb87f9b45582aff3eefdf2020afc0cc77b Mon Sep 17 00:00:00 2001 From: Darien Arthur-Gocken <233949874+DarienArthur-Gocken@users.noreply.github.com> Date: Fri, 5 Dec 2025 08:59:00 -0800 Subject: [PATCH 16/21] finishing touches on handler funcs --- src/ChatterboxClient.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/ChatterboxClient.java b/src/ChatterboxClient.java index 3a5d3ac..e24ae0e 100644 --- a/src/ChatterboxClient.java +++ b/src/ChatterboxClient.java @@ -218,8 +218,7 @@ public void authenticate() throws IOException, IllegalArgumentException { String initialPrompt = serverReader.readLine(); printToUser(initialPrompt); - this.serverWriter.write(this.username + " " + this.password + "\n"); - this.serverWriter.flush(); + writeToServer(this.username + " " + this.password); String response = serverReader.readLine(); @@ -314,7 +313,10 @@ public void printToUser(String message) throws IOException { } public void writeToServer(String message) throws IOException { - + try { + this.serverWriter.write(message + "\n"); + this.serverWriter.flush(); + } catch(IOException e) {} } public String getHost() { From e19a7cc924f857a4540f5625b1763fdd4e0074e5 Mon Sep 17 00:00:00 2001 From: Darien Arthur-Gocken <233949874+DarienArthur-Gocken@users.noreply.github.com> Date: Fri, 5 Dec 2025 09:04:28 -0800 Subject: [PATCH 17/21] send outgoing --- src/ChatterboxClient.java | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/ChatterboxClient.java b/src/ChatterboxClient.java index e24ae0e..87f7a07 100644 --- a/src/ChatterboxClient.java +++ b/src/ChatterboxClient.java @@ -299,9 +299,25 @@ public void printIncomingChats() { * print a message to userOutput and exit. */ public void sendOutgoingChats() { - // Use the userInput to read, NOT System.in directly - // loop forever reading user input - // write to serverOutput + while(true) { + String line; + if(!userInput.hasNextLine()) { + try { + Thread.sleep(50); + } catch (InterruptedException e) { } + continue; + } + line = userInput.nextLine(); + + try { + writeToServer(line); + } catch(IOException i) { + try { + printToUser("Failed to send message: " + i); + } catch (IOException e) { } + System.exit(1); + } + } } public void printToUser(String message) throws IOException { From 59dd37c0e389d2ceeb536dbd2099adc198eb987e Mon Sep 17 00:00:00 2001 From: Darien Arthur-Gocken <233949874+DarienArthur-Gocken@users.noreply.github.com> Date: Fri, 5 Dec 2025 09:25:05 -0800 Subject: [PATCH 18/21] initial threading --- src/ChatterboxClient.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/ChatterboxClient.java b/src/ChatterboxClient.java index 87f7a07..7bd7f33 100644 --- a/src/ChatterboxClient.java +++ b/src/ChatterboxClient.java @@ -9,8 +9,6 @@ import java.nio.charset.StandardCharsets; import java.util.Scanner; -import javax.imageio.IIOException; - /** * A simple command-line chat client for the Chatterbox server. * @@ -252,7 +250,10 @@ public void authenticate() throws IOException, IllegalArgumentException { * @throws IOException */ public void streamChat() throws IOException { - printIncomingChats(); + Thread incoming = new Thread(() -> printIncomingChats()); + Thread outgoing = new Thread(() -> sendOutgoingChats()); + incoming.start(); + outgoing.start(); } /** From c7d0fdb8d13313a628da8f7d33e7e3f60cfdc068 Mon Sep 17 00:00:00 2001 From: Darien Arthur-Gocken <233949874+DarienArthur-Gocken@users.noreply.github.com> Date: Fri, 5 Dec 2025 09:47:07 -0800 Subject: [PATCH 19/21] input fix --- src/ChatterboxClient.java | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/src/ChatterboxClient.java b/src/ChatterboxClient.java index 7bd7f33..eca44fa 100644 --- a/src/ChatterboxClient.java +++ b/src/ChatterboxClient.java @@ -231,10 +231,6 @@ public void authenticate() throws IOException, IllegalArgumentException { printToUser(response); - while ((response = serverReader.readLine()) != null && response.length() > 0) { - printToUser(response); - } - } /** @@ -301,22 +297,19 @@ public void printIncomingChats() { */ public void sendOutgoingChats() { while(true) { - String line; - if(!userInput.hasNextLine()) { - try { - Thread.sleep(50); - } catch (InterruptedException e) { } - continue; - } - line = userInput.nextLine(); - try { + String line = userInput.nextLine(); writeToServer(line); } catch(IOException i) { try { printToUser("Failed to send message: " + i); } catch (IOException e) { } System.exit(1); + } catch(IllegalStateException e) { + try { + printToUser("Input closed"); + } catch (IOException ex) { } + System.exit(0); } } } From 9df31e849f7101dc5433b0c0d3510cdef472a0ed Mon Sep 17 00:00:00 2001 From: Darien Arthur-Gocken <233949874+DarienArthur-Gocken@users.noreply.github.com> Date: Mon, 8 Dec 2025 12:27:22 -0800 Subject: [PATCH 20/21] catch --- my_passwords.txt | 2 -- src/ChatterboxClient.java | 8 ++------ 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/my_passwords.txt b/my_passwords.txt index 0332ee1..e69de29 100644 --- a/my_passwords.txt +++ b/my_passwords.txt @@ -1,2 +0,0 @@ -You can add your passwords here and they won't be committed to your git repository. - diff --git a/src/ChatterboxClient.java b/src/ChatterboxClient.java index eca44fa..3f42553 100644 --- a/src/ChatterboxClient.java +++ b/src/ChatterboxClient.java @@ -7,6 +7,7 @@ import java.io.OutputStreamWriter; import java.net.Socket; import java.nio.charset.StandardCharsets; +import java.util.NoSuchElementException; import java.util.Scanner; /** @@ -305,12 +306,7 @@ public void sendOutgoingChats() { printToUser("Failed to send message: " + i); } catch (IOException e) { } System.exit(1); - } catch(IllegalStateException e) { - try { - printToUser("Input closed"); - } catch (IOException ex) { } - System.exit(0); - } + } catch(NoSuchElementException e) {} } } From 340545e02be2e2ff52139b56a6a193e0c6c954e2 Mon Sep 17 00:00:00 2001 From: Darien Arthur-Gocken <233949874+DarienArthur-Gocken@users.noreply.github.com> Date: Tue, 6 Jan 2026 10:56:44 -0800 Subject: [PATCH 21/21] test --- src/ChatterboxServer.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ChatterboxServer.java b/src/ChatterboxServer.java index f10b2cc..ce5153a 100644 --- a/src/ChatterboxServer.java +++ b/src/ChatterboxServer.java @@ -158,6 +158,7 @@ public static void main(String[] args) throws IOException { * File format: * - whitespace-separated tokens * - interpreted as (user, pass) pairs + * test * * @param filename path to the credentials file * @return a map of username -> password