diff --git a/code/simplechat1/ClientConsole.java b/code/simplechat1/ClientConsole.java index c9bb4e9..7e20f33 100644 --- a/code/simplechat1/ClientConsole.java +++ b/code/simplechat1/ClientConsole.java @@ -115,7 +115,13 @@ public static void main(String[] args) { host = "localhost"; } - ClientConsole chat= new ClientConsole(host, DEFAULT_PORT); + try{ + port = Integer.parseInt(args[1]); + } + catch(Exception e){ + port = DEFAULT_PORT; + } + ClientConsole chat= new ClientConsole(host, port); chat.accept(); //Wait for console data } } diff --git a/code/simplechat1/EchoServer.java b/code/simplechat1/EchoServer.java index d4f3a1a..d0b61b7 100644 --- a/code/simplechat1/EchoServer.java +++ b/code/simplechat1/EchoServer.java @@ -71,6 +71,18 @@ protected void serverStopped() System.out.println ("Server has stopped listening for connections."); } + + protected void clientConnected(ConnectionToClient client){ + System.out.println("Client connected to server."); + } + + synchronized protected void clientDisconnected(ConnectionToClient client) { + System.out.println("Client disconnected from server."); + } + + synchronized protected void clientException(ConnectionToClient client, Throwable exception) { + System.out.println("Client disconnected from server."); + } //Class methods *************************************************** diff --git a/code/simplechat1/client/ChatClient.java b/code/simplechat1/client/ChatClient.java index fe1401e..5caf206 100644 --- a/code/simplechat1/client/ChatClient.java +++ b/code/simplechat1/client/ChatClient.java @@ -77,6 +77,17 @@ public void handleMessageFromClientUI(String message) quit(); } } + + protected void connectionClosed(){ + System.out.println("Disconnecting and quitting!"); + } + + protected void connectionException(Exception e){ + if(e instanceof IOException){ + System.out.println("The server shut down!"); + quit(); + } + } /** * This method terminates the client.