From cb284dd8075c6199e06aca6ada65bbc732b7aba3 Mon Sep 17 00:00:00 2001 From: Dragi Date: Fri, 5 Jun 2020 23:03:41 -0400 Subject: [PATCH 01/10] Created Server Interface and implemented commands into client and server components of simplechat1 --- code/simplechat1/ClientConsole.java | 15 ++-- code/simplechat1/EchoServer.java | 115 +++++++++++++++++++--------- code/simplechat1/ServerConsole.java | 102 ++++++++++++++++++++++++ 3 files changed, 189 insertions(+), 43 deletions(-) create mode 100644 code/simplechat1/ServerConsole.java diff --git a/code/simplechat1/ClientConsole.java b/code/simplechat1/ClientConsole.java index c9bb4e9..98375c6 100644 --- a/code/simplechat1/ClientConsole.java +++ b/code/simplechat1/ClientConsole.java @@ -72,14 +72,19 @@ public void accept() while (true) { - message = fromConsole.readLine(); - client.handleMessageFromClientUI(message); + message = fromConsole.readLine(); + if (message.equals("#sethost")) { + // User didn't enter full command for changing host + System.out.println("No host specified. Using default host..."); + client.handleMessageFromClientUI("#sethost localhost"); + } + else + client.handleMessageFromClientUI(message); } } catch (Exception ex) { - System.out.println - ("Unexpected error while reading from console!"); + System.out.println("Could not read from console!"); } } @@ -87,7 +92,7 @@ public void accept() * This method overrides the method in the ChatIF interface. It * displays a message onto the screen. * - * @param message The string to be displayed. + * @param message The string fto be displayed. */ public void display(String message) { diff --git a/code/simplechat1/EchoServer.java b/code/simplechat1/EchoServer.java index d4f3a1a..96b7a30 100644 --- a/code/simplechat1/EchoServer.java +++ b/code/simplechat1/EchoServer.java @@ -4,6 +4,7 @@ import java.io.*; import ocsf.server.*; +import common.*; /** * This class overrides some of the methods in the abstract @@ -17,13 +18,6 @@ */ public class EchoServer extends AbstractServer { - //Class variables ************************************************* - - /** - * The default port to listen on. - */ - final public static int DEFAULT_PORT = 5555; - //Constructors **************************************************** /** @@ -36,6 +30,14 @@ public EchoServer(int port) super(port); } + //Instance variables ********************************************** + + /** + * The interface type variable. It allows the implementation of + * the display method in the server. + */ + ChatIF serverUI; + //Instance methods ************************************************ @@ -51,7 +53,68 @@ public EchoServer(int port) System.out.println("Message received: " + msg + " from " + client); this.sendToAllClients(msg); } - + + /** + * This method reads user input's from the console + * + * @param in Input from the console + */ + public void handleInputFromServerConsole(String input) + { + // Check if message is a command + if (input.charAt(0) == '#') { + // Split the message into two + String[] mes = input.split(" ", 2); + // Select appropriate function + switch(mes[0]) { + case "#quit": + try { + close(); + } + catch(IOException e) + { + System.out.println(": " + e); + } + break; + case "#stop": + stopListening(); + break; + case "#close": + System.out.println("Not implemented!"); + break; + case "#setport": + try { + setPort(Integer.parseInt(mes[1])); + } + catch (Exception e) { + System.out.println("No port specified. Using default port..."); + setPort(5555); + } + break; + case "#start": + try { + listen(); + } + catch(IOException e) + { + System.out.println(": " + e); + } + break; + case "#getport": + System.out.println(getPort()); + break; + default: + System.out.println("Command not valid!"); + break; + } + } + else + { + // Send everything to the clients + this.sendToAllClients(input); + } + } + /** * This method overrides the one in the superclass. Called * when the server starts listening for connections. @@ -71,39 +134,15 @@ protected void serverStopped() System.out.println ("Server has stopped listening for connections."); } - - //Class methods *************************************************** - + /** - * This method is responsible for the creation of - * the server instance (there is no UI in this phase). - * - * @param args[0] The port number to listen on. Defaults to 5555 - * if no argument is entered. + * This method overrides the one in the superclass. Called + * when the server closes. */ - public static void main(String[] args) + protected void serverClosed() { - int port = 0; //Port to listen on - - try - { - port = Integer.parseInt(args[0]); //Get port from command line - } - catch(Throwable t) - { - port = DEFAULT_PORT; //Set port to 5555 - } - - EchoServer sv = new EchoServer(port); - - try - { - sv.listen(); //Start listening for connections - } - catch (Exception ex) - { - System.out.println("ERROR - Could not listen for clients!"); - } + System.out.println("Disconnecting all clients..."); + System.exit(0); } } //End of EchoServer class diff --git a/code/simplechat1/ServerConsole.java b/code/simplechat1/ServerConsole.java new file mode 100644 index 0000000..7ef191a --- /dev/null +++ b/code/simplechat1/ServerConsole.java @@ -0,0 +1,102 @@ +import common.*; +import java.io.*; + +public class ServerConsole implements ChatIF { + //Instance variables ********************************************** + + /** + * The instance of the server that created this EchoServer. + */ + EchoServer sv; + + //Constructors **************************************************** + + /** + * Constructs an instance of the ServerConsole UI. + * + * @param port The port that server listens to. + */ + public ServerConsole(int port) + { + sv = new EchoServer(port); + } + + //Instance methods ************************************************ + /** + * This method overrides the method in the ChatIF interface. It + * displays a message onto the screen. + * + * @param message The string fto be displayed. + */ + public void display(String message) + { + System.out.println("SERVER MSG> " + message); + } + + /** + * This method allows the user of console for commands and + * messages to the client + */ + public void console() { + try + { + BufferedReader fromConsole = + new BufferedReader(new InputStreamReader(System.in)); + String input; + sv.listen(); + + while (true) + { + input = fromConsole.readLine(); + sv.handleInputFromServerConsole(input); + } + } + catch (Exception ex) + { + System.out.println + ("Unexpected error while reading from console!"); + } + } + + //Class variables ************************************************* + + /** + * The default port to listen on. + */ + final public static int DEFAULT_PORT = 5555; + + //Class methods *************************************************** + + /** + * This method is responsible for the creation of + * the server instance (there is no UI in this phase). + * + * @param args[0] The port number to listen on. Defaults to 5555 + * if no argument is entered. + */ + public static void main(String[] args) + { + int port = 0; //Port to listen on + + try + { + port = Integer.parseInt(args[0]); //Get port from command line + } + catch(Throwable t) + { + port = DEFAULT_PORT; //Set port to 5555 + } + + ServerConsole serv = new ServerConsole(port); + + try + { + serv.console(); // Allow access to server console + } + catch (Exception ex) + { + System.out.println("ERROR - Could not listen for clients!"); + } + } + +} From 22c255403bc1e86caf0f4e0e372861e7bd216385 Mon Sep 17 00:00:00 2001 From: Dragi Date: Sat, 6 Jun 2020 12:32:01 -0400 Subject: [PATCH 02/10] Fixed bugs in EchoServer related to user-given commands --- code/simplechat1/ClientConsole.java | 2 +- code/simplechat1/EchoServer.java | 33 ++++++++++------------------- 2 files changed, 12 insertions(+), 23 deletions(-) diff --git a/code/simplechat1/ClientConsole.java b/code/simplechat1/ClientConsole.java index 98375c6..175c019 100644 --- a/code/simplechat1/ClientConsole.java +++ b/code/simplechat1/ClientConsole.java @@ -96,7 +96,7 @@ public void accept() */ public void display(String message) { - System.out.println("> " + message); + System.out.println(message); } diff --git a/code/simplechat1/EchoServer.java b/code/simplechat1/EchoServer.java index 96b7a30..01f8725 100644 --- a/code/simplechat1/EchoServer.java +++ b/code/simplechat1/EchoServer.java @@ -67,7 +67,7 @@ public void handleInputFromServerConsole(String input) String[] mes = input.split(" ", 2); // Select appropriate function switch(mes[0]) { - case "#quit": + case "#close": try { close(); } @@ -79,8 +79,15 @@ public void handleInputFromServerConsole(String input) case "#stop": stopListening(); break; - case "#close": - System.out.println("Not implemented!"); + case "#quit": + try { + close(); + System.exit(0); + } + catch(IOException e) + { + System.out.println(": " + e); + } break; case "#setport": try { @@ -110,6 +117,7 @@ public void handleInputFromServerConsole(String input) } else { + input += ("#server"); // Add identifier // Send everything to the clients this.sendToAllClients(input); } @@ -125,24 +133,5 @@ protected void serverStarted() ("Server listening for connections on port " + getPort()); } - /** - * This method overrides the one in the superclass. Called - * when the server stops listening for connections. - */ - protected void serverStopped() - { - System.out.println - ("Server has stopped listening for connections."); - } - - /** - * This method overrides the one in the superclass. Called - * when the server closes. - */ - protected void serverClosed() - { - System.out.println("Disconnecting all clients..."); - System.exit(0); - } } //End of EchoServer class From f97345db32b77a38169a14c8b372c59ce3b1b53c Mon Sep 17 00:00:00 2001 From: Dragi Date: Sat, 6 Jun 2020 19:17:38 -0400 Subject: [PATCH 03/10] Added login option with ID for the client --- code/simplechat1/ClientConsole.java | 16 +++--- code/simplechat1/client/ChatClient.java | 71 +++++++++++++++++++++++-- 2 files changed, 77 insertions(+), 10 deletions(-) diff --git a/code/simplechat1/ClientConsole.java b/code/simplechat1/ClientConsole.java index 175c019..928217b 100644 --- a/code/simplechat1/ClientConsole.java +++ b/code/simplechat1/ClientConsole.java @@ -62,13 +62,15 @@ public ClientConsole(String host, int port) * This method waits for input from the console. Once it is * received, it sends it to the client's message handler. */ - public void accept() + public void accept(String login) { try { BufferedReader fromConsole = new BufferedReader(new InputStreamReader(System.in)); String message; + String cmd = ("#login " + login); + client.handleMessageFromClientUI(cmd); while (true) { @@ -105,23 +107,25 @@ public void display(String message) /** * This method is responsible for the creation of the Client UI. * - * @param args[0] The host to connect to. + * @param args[0] Login-id of the user to connect to a server. */ public static void main(String[] args) { - String host = ""; + String clientID = ""; + String host = "localhost"; int port = 0; //The port number try { - host = args[0]; + clientID = args[0]; } catch(ArrayIndexOutOfBoundsException e) { - host = "localhost"; + System.out.println("ERROR - No login ID specified. Connection aborted."); + System.exit(1); } ClientConsole chat= new ClientConsole(host, DEFAULT_PORT); - chat.accept(); //Wait for console data + chat.accept(clientID); //Wait for console data } } //End of ConsoleChat class diff --git a/code/simplechat1/client/ChatClient.java b/code/simplechat1/client/ChatClient.java index fe1401e..4682f28 100644 --- a/code/simplechat1/client/ChatClient.java +++ b/code/simplechat1/client/ChatClient.java @@ -56,7 +56,14 @@ public ChatClient(String host, int port, ChatIF clientUI) */ public void handleMessageFromServer(Object msg) { - clientUI.display(msg.toString()); + String message = msg.toString(); + if (message.contains("#server")) { + int ind = message.indexOf('#'); + String mes = message.substring(0, ind); + clientUI.display("SERVER MSG> " + mes); + } + else + clientUI.display("> " + message); } /** @@ -68,7 +75,63 @@ public void handleMessageFromClientUI(String message) { try { - sendToServer(message); + // Check if message is a command + if (message.charAt(0) == '#') { + // Split the message into two + String[] mes = message.split(" ", 3); + if (mes[0].equals("#login") || mes.length == 2) { + sendToServer(message); + } + else { + // Select appropriate function + switch(mes[0]) { + case "#quit": + // Break the connection and close the client + closeConnection(); + System.exit(0); // Indicate succesful exit + break; + case "#logoff": + // Break the connection + closeConnection(); + break; + case "#sethost": + // Send the argument of the command to the function + if (mes[1].equals("")) + setHost("localhost"); + else + setHost(mes[1]); + break; + case "#setport": + // Convert argument of the command to int and pass it + try { + setPort(Integer.parseInt(mes[1])); + } + catch (Exception e) { + System.out.println("No port supplied. Using default...."); + setPort(5555); + } + break; + case "#login": + // Open connection only if connection is closed + if (!(isConnected())) + openConnection(); + else + System.out.println("You must logoff first before login"); + break; + case "#gethost": + System.out.println(getHost()); + break; + case "#getport": + System.out.println(getPort()); + break; + default: + System.out.println("Command not valid!"); + break; + } + } + } + else + sendToServer(message); } catch(IOException e) { @@ -76,8 +139,8 @@ public void handleMessageFromClientUI(String message) ("Could not send message to server. Terminating client."); quit(); } - } - + } + /** * This method terminates the client. */ From 31e9533c15f1a671806f265841fac0f71ae30284 Mon Sep 17 00:00:00 2001 From: Dragi Date: Sun, 7 Jun 2020 14:58:06 -0400 Subject: [PATCH 04/10] Added support for command line arguments in ClientConsole.java --- code/simplechat1/ClientConsole.java | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/code/simplechat1/ClientConsole.java b/code/simplechat1/ClientConsole.java index 928217b..7c39e93 100644 --- a/code/simplechat1/ClientConsole.java +++ b/code/simplechat1/ClientConsole.java @@ -112,19 +112,42 @@ public void display(String message) public static void main(String[] args) { String clientID = ""; - String host = "localhost"; + String host = ""; int port = 0; //The port number try { - clientID = args[0]; + // Given that only clientID argument is mandatory, check if user entered additional arguments + if (args.length == 3) { + clientID = args[0]; + host = args[1]; + port = Integer.parseInt(args[2]); + + } + else if (args.length == 2) { + // Determine the type of argument. Assume that second argument is port argument + clientID = args[0]; + port = Integer.parseInt(args[1]); + host = "localhost"; + } + else + clientID = args[0]; + host = "localhost"; + port = DEFAULT_PORT; } catch(ArrayIndexOutOfBoundsException e) { System.out.println("ERROR - No login ID specified. Connection aborted."); System.exit(1); } - ClientConsole chat= new ClientConsole(host, DEFAULT_PORT); + // The assumption was wrong. + catch (NumberFormatException e) + { + // Use the default port + port = DEFAULT_PORT; + host = args[1]; + } + ClientConsole chat= new ClientConsole(host, port); chat.accept(clientID); //Wait for console data } } From cbfdc4a0fa5ef51fc6c4458c891ab5e657ab1869 Mon Sep 17 00:00:00 2001 From: Dragi Date: Sat, 13 Jun 2020 15:15:09 -0400 Subject: [PATCH 05/10] Remove automatic quitting if client is not connected --- code/simplechat1/EchoServer.java | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/code/simplechat1/EchoServer.java b/code/simplechat1/EchoServer.java index 01f8725..b16c7ab 100644 --- a/code/simplechat1/EchoServer.java +++ b/code/simplechat1/EchoServer.java @@ -36,7 +36,7 @@ public EchoServer(int port) * The interface type variable. It allows the implementation of * the display method in the server. */ - ChatIF serverUI; + ChatIF serverUI; //Instance methods ************************************************ @@ -50,10 +50,22 @@ public EchoServer(int port) public void handleMessageFromClient (Object msg, ConnectionToClient client) { - System.out.println("Message received: " + msg + " from " + client); - this.sendToAllClients(msg); + String mes = (String) msg; + // Don't display the command to the server interface and send it to other clients + if (mes.contains("#login")) + { + int ind = mes.indexOf(" "); + int len = mes.length(); + String ID = mes.substring(ind, len); + client.setInfo("Login ID", ID); + } + else { + System.out.println("Message received: " + msg + " from " + client); + this.sendToAllClients(msg); + } } + /** * This method reads user input's from the console * From 874b3587531b53ac2869fb06cc6ed6db692e3f66 Mon Sep 17 00:00:00 2001 From: Dragi Date: Sun, 14 Jun 2020 03:01:07 -0400 Subject: [PATCH 06/10] Fixed display function --- code/simplechat1/ClientConsole.java | 42 +++++++++++++++++------------ 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/code/simplechat1/ClientConsole.java b/code/simplechat1/ClientConsole.java index 7c39e93..79fa656 100644 --- a/code/simplechat1/ClientConsole.java +++ b/code/simplechat1/ClientConsole.java @@ -41,18 +41,9 @@ public class ClientConsole implements ChatIF * @param host The host to connect to. * @param port The port to connect on. */ - public ClientConsole(String host, int port) + public ClientConsole(String host, int port, String id) { - try - { - client= new ChatClient(host, port, this); - } - catch(IOException exception) - { - System.out.println("Error: Can't setup connection!" - + " Terminating client."); - System.exit(1); - } + client= new ChatClient(host, port, id, this); } @@ -62,24 +53,24 @@ public ClientConsole(String host, int port) * This method waits for input from the console. Once it is * received, it sends it to the client's message handler. */ - public void accept(String login) + public void accept() { try { BufferedReader fromConsole = new BufferedReader(new InputStreamReader(System.in)); String message; - String cmd = ("#login " + login); - client.handleMessageFromClientUI(cmd); while (true) { message = fromConsole.readLine(); + // For commands passed if (message.equals("#sethost")) { // User didn't enter full command for changing host System.out.println("No host specified. Using default host..."); client.handleMessageFromClientUI("#sethost localhost"); } + // No commands passed. Just plain messages else client.handleMessageFromClientUI(message); } @@ -98,7 +89,24 @@ public void accept(String login) */ public void display(String message) { - System.out.println(message); + if (message.contains("#server")) { + // Remove #server and display server's maessage + int index = message.indexOf('#'); + String mes = message.substring(0, index); + System.out.println("SERVER MSG> " + mes); + } + else { + // Split the message and print: loginID> msg (messages) + if (message.contains(" has loged on")) { + String[] mes = message.split(" ", 2); + System.out.println(mes[0] + " " + mes[1]); + } + else { + String[] mes = message.split(" ", 2); + System.out.println(mes[0] + "> " + mes[1]); + } + } + } @@ -147,8 +155,8 @@ else if (args.length == 2) { port = DEFAULT_PORT; host = args[1]; } - ClientConsole chat= new ClientConsole(host, port); - chat.accept(clientID); //Wait for console data + ClientConsole chat= new ClientConsole(host, port, clientID); + chat.accept(); //Wait for console data } } //End of ConsoleChat class From c0e5579d4f7797339501c305d8eb29f5b56d19eb Mon Sep 17 00:00:00 2001 From: Dragi Date: Sun, 14 Jun 2020 03:02:29 -0400 Subject: [PATCH 07/10] Allowed client to run despite no server connection --- code/simplechat1/client/ChatClient.java | 55 ++++++++++++++++--------- 1 file changed, 36 insertions(+), 19 deletions(-) diff --git a/code/simplechat1/client/ChatClient.java b/code/simplechat1/client/ChatClient.java index 4682f28..f3f89fd 100644 --- a/code/simplechat1/client/ChatClient.java +++ b/code/simplechat1/client/ChatClient.java @@ -25,7 +25,10 @@ public class ChatClient extends AbstractClient * The interface type variable. It allows the implementation of * the display method in the client. */ - ChatIF clientUI; + ChatIF clientUI; + + // Variable to store login id + String loginID; //Constructors **************************************************** @@ -38,12 +41,23 @@ public class ChatClient extends AbstractClient * @param clientUI The interface type variable. */ - public ChatClient(String host, int port, ChatIF clientUI) - throws IOException +// Don't try to connect immediately + public ChatClient(String host, int port, String ID, ChatIF clientUI) { super(host, port); //Call the superclass constructor this.clientUI = clientUI; - openConnection(); + this.loginID = ID; + + // Try to open connection + try { + openConnection(); + // Send the server command for logging in the user + sendToServer("#login " + ID); + } + catch(IOException exception) + { + System.out.println("Cannot open connection. Awaiting command."); + } } @@ -56,14 +70,7 @@ public ChatClient(String host, int port, ChatIF clientUI) */ public void handleMessageFromServer(Object msg) { - String message = msg.toString(); - if (message.contains("#server")) { - int ind = message.indexOf('#'); - String mes = message.substring(0, ind); - clientUI.display("SERVER MSG> " + mes); - } - else - clientUI.display("> " + message); + clientUI.display((String)msg); } /** @@ -78,8 +85,11 @@ public void handleMessageFromClientUI(String message) // Check if message is a command if (message.charAt(0) == '#') { // Split the message into two - String[] mes = message.split(" ", 3); - if (mes[0].equals("#login") || mes.length == 2) { + String[] mes = message.split(" ", 4); + if (mes[0].equals("#login") && mes.length == 2) { + // Open the connection if it is still closed + if (!(isConnected())) + openConnection(); sendToServer(message); } else { @@ -96,25 +106,33 @@ public void handleMessageFromClientUI(String message) break; case "#sethost": // Send the argument of the command to the function - if (mes[1].equals("")) + if (mes[1].equals("")) { setHost("localhost"); - else + System.out.println("Host set to: " + getHost()); + } + else { setHost(mes[1]); + System.out.println("Host set to: " + getHost()); + } break; case "#setport": // Convert argument of the command to int and pass it try { setPort(Integer.parseInt(mes[1])); + System.out.println("Port set to: " + getPort()); } catch (Exception e) { System.out.println("No port supplied. Using default...."); setPort(5555); + System.out.println("Port set to: " + getPort()); } break; case "#login": // Open connection only if connection is closed - if (!(isConnected())) + if (!(isConnected())) { openConnection(); + sendToServer("#login " + loginID); + } else System.out.println("You must logoff first before login"); break; @@ -136,8 +154,7 @@ public void handleMessageFromClientUI(String message) catch(IOException e) { clientUI.display - ("Could not send message to server. Terminating client."); - quit(); + ("Cannot open connection. Awaiting command."); } } From 79fa89033b9335c468f502ef943dfa58c869d5f9 Mon Sep 17 00:00:00 2001 From: Dragi Date: Sun, 14 Jun 2020 03:03:44 -0400 Subject: [PATCH 08/10] Add support for #close #stop #start --- code/simplechat1/EchoServer.java | 41 ++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/code/simplechat1/EchoServer.java b/code/simplechat1/EchoServer.java index b16c7ab..9bd6f04 100644 --- a/code/simplechat1/EchoServer.java +++ b/code/simplechat1/EchoServer.java @@ -54,18 +54,32 @@ public EchoServer(int port) // Don't display the command to the server interface and send it to other clients if (mes.contains("#login")) { - int ind = mes.indexOf(" "); - int len = mes.length(); - String ID = mes.substring(ind, len); - client.setInfo("Login ID", ID); + // Log the user into the system + int ind = mes.indexOf(" "); // Start of identification string + int len = mes.length(); // End of identiification string + String ID = mes.substring(ind+1, len); + client.setInfo("Login ID", ID); + + // Indicate who connected to the administrator + System.out.println("A new client is attempting to connect to the server."); + System.out.println("Message received #login " + client.getInfo("Login ID") + " from null."); + System.out.println(client.getInfo("Login ID") + " has logged on."); + try { + // Add > so that client's console does not mistake the login as a message + client.sendToClient(client.getInfo("Login ID") + " has logged on."); + } + catch (IOException e) { + System.out.println("Could not notify the client!"); + } + + } else { - System.out.println("Message received: " + msg + " from " + client); - this.sendToAllClients(msg); + System.out.println("Message received: " + msg + " from " + client.getInfo("Login ID")); + this.sendToAllClients(client.getInfo("Login ID") + " " + msg); } } - /** * This method reads user input's from the console * @@ -144,6 +158,19 @@ protected void serverStarted() System.out.println ("Server listening for connections on port " + getPort()); } + + protected void serverStopped() + { + System.out.println + ("Server has stopped listening for connections."); + sendToAllClients("WARNING - Server has stopped listening for connections."); + } + + protected void serverClosed() + { + System.out.println("Server is closed"); + sendToAllClients("WARNING - The server has stopped listening for connections. SERVER SHUTTING DOWN! DISCONNECTING!"); + } } //End of EchoServer class From 0d2e183a6d565ee8f60ee4d8a7bea8516b58256c Mon Sep 17 00:00:00 2001 From: Dragi Date: Sun, 14 Jun 2020 03:20:04 -0400 Subject: [PATCH 09/10] Added echo for server console --- code/simplechat1/EchoServer.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/code/simplechat1/EchoServer.java b/code/simplechat1/EchoServer.java index 9bd6f04..939908d 100644 --- a/code/simplechat1/EchoServer.java +++ b/code/simplechat1/EchoServer.java @@ -143,8 +143,11 @@ public void handleInputFromServerConsole(String input) } else { + + // Echo to the server console + System.out.println("SERVER MESSAGE> " + input); + // Send to the clients input += ("#server"); // Add identifier - // Send everything to the clients this.sendToAllClients(input); } } From fefba57ede016eabae60732edd9a1b28ac9b686a Mon Sep 17 00:00:00 2001 From: Dragi Date: Sun, 14 Jun 2020 03:30:43 -0400 Subject: [PATCH 10/10] Added logoff message --- code/simplechat1/client/ChatClient.java | 1 + 1 file changed, 1 insertion(+) diff --git a/code/simplechat1/client/ChatClient.java b/code/simplechat1/client/ChatClient.java index f3f89fd..f523686 100644 --- a/code/simplechat1/client/ChatClient.java +++ b/code/simplechat1/client/ChatClient.java @@ -101,6 +101,7 @@ public void handleMessageFromClientUI(String message) System.exit(0); // Indicate succesful exit break; case "#logoff": + System.out.println(loginID + " has disconnected."); // Break the connection closeConnection(); break;