From a3f19f34f029ae530ae33f486884443ae0c547c2 Mon Sep 17 00:00:00 2001 From: ShaanBhoi <46392837+ShaanBhoi@users.noreply.github.com> Date: Fri, 12 Jun 2020 22:12:30 -0400 Subject: [PATCH 01/11] First push is a test, i changed the first line in EchoServer.java to have //Shaan Bhoi --- code/simplechat1/EchoServer.java | 1 + 1 file changed, 1 insertion(+) diff --git a/code/simplechat1/EchoServer.java b/code/simplechat1/EchoServer.java index d4f3a1a..68f4fc2 100644 --- a/code/simplechat1/EchoServer.java +++ b/code/simplechat1/EchoServer.java @@ -1,3 +1,4 @@ +// Test push // This file contains material supporting section 3.7 of the textbook: // "Object Oriented Software Engineering" and is issued under the open-source // license found at www.lloseng.com From 30ede03fdb21509d78e550128c65b178ca15dd9e Mon Sep 17 00:00:00 2001 From: ShaanBhoi <46392837+ShaanBhoi@users.noreply.github.com> Date: Fri, 12 Jun 2020 23:06:26 -0400 Subject: [PATCH 02/11] Implemented E5a for client side, added override methods in ChatClient.java for the methods : connectionClosed , connectionException , and connectionEstablished. --- code/simplechat1/.DS_Store | Bin 0 -> 6148 bytes code/simplechat1/client/ChatClient.java | 60 ++++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 code/simplechat1/.DS_Store diff --git a/code/simplechat1/.DS_Store b/code/simplechat1/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..b3aefda13c8bbbe4f0311f20172be0bedbba551b GIT binary patch literal 6148 zcmeHKyG{c!5S)bwMM{&B(!anTSW)0#ZN*bAq`_;hfH z7J#^5IE?e?C5X)f#9lZhGD5SY5|e7xVp!4{Z~aH_y{F4tcF@9BT^|EDCaq<|E-C-EB8~rK+v7m-AZN=nr(y`J}sX9uy8y lj)_r@x$ts)8%dehe9rw|I3)(1@t_m+GvK<&q`-eG@CAc{8-4%) literal 0 HcmV?d00001 diff --git a/code/simplechat1/client/ChatClient.java b/code/simplechat1/client/ChatClient.java index fe1401e..af6eb03 100644 --- a/code/simplechat1/client/ChatClient.java +++ b/code/simplechat1/client/ChatClient.java @@ -90,5 +90,65 @@ public void quit() catch(IOException e) {} System.exit(0); } + + /** + * Hook method called after the connection has been closed. The default + * implementation does nothing. The method may be overriden by subclasses to + * perform special processing such as cleaning up and terminating, or + * attempting to reconnect. + */ + protected void connectionClosed() { + System.out.println("The connection to the server has been closed."); + } + + /** + * Hook method called each time an exception is thrown by the client's + * thread that is waiting for messages from the server. The method may be + * overridden by subclasses. + * + * @param exception + * the exception raised. + */ + protected void connectionException(Exception exception) { + System.out.println("The server has shut down. \nQuitting...") + quit(); + } + + /** + * Hook method called after a connection has been established. The default + * implementation does nothing. It may be overridden by subclasses to do + * anything they wish. + */ + protected void connectionEstablished() { + System.out.println("Connection established"); + } } //End of ChatClient class + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 26a684e05de017ec28f6af3fcef49276995bded7 Mon Sep 17 00:00:00 2001 From: ShaanBhoi <46392837+ShaanBhoi@users.noreply.github.com> Date: Sat, 13 Jun 2020 00:23:22 -0400 Subject: [PATCH 03/11] Implemented E5c for server side, added overide methods in EchoServer.java for the methods: clientConnected , clientDisconnected, and clientException --- code/.DS_Store | Bin 0 -> 6148 bytes code/ocsf/.DS_Store | Bin 0 -> 6148 bytes code/simplechat1/.DS_Store | Bin 6148 -> 6148 bytes code/simplechat1/EchoServer.java | 35 ++++++++++++++++++++++++ code/simplechat1/client/ChatClient.java | 6 ++-- 5 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 code/.DS_Store create mode 100644 code/ocsf/.DS_Store diff --git a/code/.DS_Store b/code/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..d91f717ee0fef530fe6eae00ddf11ece6c9f642a GIT binary patch literal 6148 zcmeHKOKQU~5Pj2n5t>bwS?UVu2}DRw&%Y1+Mx-Zz>t#Ke$ID8$Tw^hWcM zr3aQY0A%~S-vBEB3pPbjWkS?E>ALaYhA2A6{?K+Wecy3#Euw30(4)lxZ^!Gu8;tnD zE1lYZ9|tUH{JF$^Jb+?u~72uxER+ zAAB5$jRS(O_QCP{U~b5yfE17dQa}nwfpZn8N;+Shdw_USKnh%}0{lKSII$OwiSg;c z5G??3hHx0>(Mtdu1HfK5CL#j!qym%b)na(k5pR{(3&+Hyo5#&Kr*8J@P&{r&yhXZs zPt+&{q`;{H*STD>{@=s@=>JbiT1f#Za8U~QZ2hoa;Yn3nCy!&TZSW18IiGME=0U*_ lu;+epg1#yR$T;g}e7#Dfmh&j59iNrC@X;0wxc8;k$| literal 0 HcmV?d00001 diff --git a/code/simplechat1/.DS_Store b/code/simplechat1/.DS_Store index b3aefda13c8bbbe4f0311f20172be0bedbba551b..bff32e4b8dd783d0e575936df2a2c20d5cf82fa2 100644 GIT binary patch delta 18 acmZoMXfc?ucVdeA#tX{qo7p-3@&f=#MF&d& delta 16 XcmZoMXfc?umyvPfK{xirEF1y=GYADX diff --git a/code/simplechat1/EchoServer.java b/code/simplechat1/EchoServer.java index 68f4fc2..6d6f49d 100644 --- a/code/simplechat1/EchoServer.java +++ b/code/simplechat1/EchoServer.java @@ -39,6 +39,41 @@ public EchoServer(int port) //Instance methods ************************************************ + /** + * Hook method called each time a new client connection is + * accepted. The default implementation does nothing. + * @param client the connection connected to the client. + */ + protected void clientConnected(ConnectionToClient client) { + System.out.println("A new user has connected to the server."); + } + + /** + * Hook method called each time a client disconnects. + * The default implementation does nothing. The method + * may be overridden by subclasses but should remains synchronized. + * + * @param client the connection with the client. + */ + synchronized protected void clientDisconnected( + ConnectionToClient client) { + System.out.println("A user has disconnected from the server."); + } + + /** + * Hook method called each time an exception is thrown in a + * ConnectionToClient thread. + * The method may be overridden by subclasses but should remains + * synchronized. + * + * @param client the client that raised the exception. + * @param Throwable the exception thrown. + */ + synchronized protected void clientException( + ConnectionToClient client, Throwable exception) { + clientDisconnected(client); + } + /** * This method handles any messages received from the client. diff --git a/code/simplechat1/client/ChatClient.java b/code/simplechat1/client/ChatClient.java index af6eb03..9c91077 100644 --- a/code/simplechat1/client/ChatClient.java +++ b/code/simplechat1/client/ChatClient.java @@ -110,7 +110,7 @@ protected void connectionClosed() { * the exception raised. */ protected void connectionException(Exception exception) { - System.out.println("The server has shut down. \nQuitting...") + System.out.println("The server has shut down. \nQuitting..."); quit(); } @@ -120,8 +120,10 @@ protected void connectionException(Exception exception) { * anything they wish. */ protected void connectionEstablished() { - System.out.println("Connection established"); + System.out.println("The connection to the server has been established."); } + + } //End of ChatClient class From d5e05a23aea20559b55961d61556587c33e56b64 Mon Sep 17 00:00:00 2001 From: ShaanBhoi <46392837+ShaanBhoi@users.noreply.github.com> Date: Sat, 13 Jun 2020 21:06:38 -0400 Subject: [PATCH 04/11] Implemented E6a for client side, added commands quit,logoff,sethost,setport,login,gethost,getport --- code/simplechat1/client/ChatClient.java | 108 ++++++++++++++++++++++-- 1 file changed, 100 insertions(+), 8 deletions(-) diff --git a/code/simplechat1/client/ChatClient.java b/code/simplechat1/client/ChatClient.java index 9c91077..dc549da 100644 --- a/code/simplechat1/client/ChatClient.java +++ b/code/simplechat1/client/ChatClient.java @@ -62,11 +62,9 @@ public void handleMessageFromServer(Object msg) /** * This method handles all data coming from the UI * - * @param message The message from the UI. - */ - public void handleMessageFromClientUI(String message) - { - try + * @param message The message from the UI. + + try { sendToServer(message); } @@ -76,6 +74,100 @@ public void handleMessageFromClientUI(String message) ("Could not send message to server. Terminating client."); quit(); } + + + */ + public void handleMessageFromClientUI(String message){ + + if (message.equals("#quit")) { + clientUI.display("Quitting..."); + quit(); + } + + else if (message.equals("#logoff")) { + try { + closeConnection(); + } + catch (IOException ignored){ + return; + } + + } + + else if (message.startsWith("#sethost")) { + if (isConnected()) { + clientUI.display("Invalid command\n Can not set host once logged in\nPlease log out first with command #logoff"); + return; + } + + else if (!isConnected()) { + try{ + String host = message.split("\\s+")[1]; + setHost(host); + clientUI.display("Host server has been set to: " +host); + } + catch(Exception e){ + clientUI.display("Invalid host server."); + return; + } + } + } + + else if (message.startsWith("#setport")) { + if (isConnected()) { + clientUI.display("Invalid command\n Can not set port once logged in\nPlease log out first with command #logoff"); + return; + + } + + else if (!isConnected()) { + try{ + int port = Integer.parseInt(message.split("\\s+")[1]); + setPort(port); + clientUI.display("Port has been set to: " +port); + } + catch(Exception e){ + clientUI.display("Invalid port."); + return; + } + } + } + + else if (message.equals("#login")) { + if (isConnected()) { + clientUI.display("Invalid command\n Can not log in once logged in\nPlease log out first with command #logoff"); + return; + } + + else if (!isConnected()) { + try{ + openConnection(); + clientUI.display("Loggin in."); + } + catch(IOException e){ + clientUI.display("Unable to log in."); + } + } + } + + else if (message.equals("#gethost")) { + clientUI.display("Host: "+getHost()); + } + else if (message.equals("#getport")) { + clientUI.display("Port: "+getPort()); + } + else if (message.startsWith("#")) { + clientUI.display("Invalid command. Please try again.\nPossible commands are :\n\n#quit\t: to quit\n#logoff\t: to log off\n#sethost\t: to set host if logged off\n#setport\t: to set port if logged off\n#login\t: to log in if not logged in already\n#gethost\t: to get the current host\n#getport\t: to get the current port"); + } + else{ + try{ + sendToServer(message); + } + catch(IOException e){ + clientUI.display("Could not send message to server.\nTerminating client."); + quit(); + } + } } /** @@ -98,7 +190,7 @@ public void quit() * attempting to reconnect. */ protected void connectionClosed() { - System.out.println("The connection to the server has been closed."); + clientUI.display("The connection to the server has been closed."); } /** @@ -110,7 +202,7 @@ protected void connectionClosed() { * the exception raised. */ protected void connectionException(Exception exception) { - System.out.println("The server has shut down. \nQuitting..."); + clientUI.display("The server has shut down. \nQuitting..."); quit(); } @@ -120,7 +212,7 @@ protected void connectionException(Exception exception) { * anything they wish. */ protected void connectionEstablished() { - System.out.println("The connection to the server has been established."); + clientUI.display("The connection to the server has been established."); } From b68c717f314a9ac500c55419c3bc110499760f35 Mon Sep 17 00:00:00 2001 From: ShaanBhoi <46392837+ShaanBhoi@users.noreply.github.com> Date: Sun, 14 Jun 2020 03:33:12 -0400 Subject: [PATCH 05/11] serverside not working properly, E6 --- .DS_Store | Bin 0 -> 6148 bytes V2Code/.DS_Store | Bin 0 -> 6148 bytes V2Code/com/.DS_Store | Bin 0 -> 6148 bytes V2Code/com/lloseng/.DS_Store | Bin 0 -> 6148 bytes V2Code/com/lloseng/ocsf/.DS_Store | Bin 0 -> 6148 bytes code/.DS_Store | Bin 6148 -> 6148 bytes code/postal/.DS_Store | Bin 0 -> 6148 bytes code/simplechat1/.DS_Store | Bin 6148 -> 6148 bytes code/simplechat1/EchoServer.java | 79 ++++++++++++++++- code/simplechat1/ServerConsole.java | 131 ++++++++++++++++++++++++++++ 10 files changed, 208 insertions(+), 2 deletions(-) create mode 100644 .DS_Store create mode 100644 V2Code/.DS_Store create mode 100644 V2Code/com/.DS_Store create mode 100644 V2Code/com/lloseng/.DS_Store create mode 100644 V2Code/com/lloseng/ocsf/.DS_Store create mode 100644 code/postal/.DS_Store create mode 100644 code/simplechat1/ServerConsole.java diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..5bf02b4b0a498501b704963e443144f872824151 GIT binary patch literal 6148 zcmeHKyG{c!5S%3^6p1D!rGEjwzzX3DB2go9bdjz=^jGm+d>XTlg6M*jh6ZM(_1Nnj zTb|GjRIO~s^u6!_N)`1hgF9ed%N7@rOf(E<<$hQm0I zUV_*>KH1@V-^m;4I%_5-~tF3K^+i#j?VMXLSaS~dY0@jc51bKLsN^0 z?w;4J$RHv;+$b9h6I0}!Tx68{^>MkK$MI$*w?)zl@IfZ~xlK?3DnJFO02QDDGg2TA z@_sd=XX2w!0V*&L1?>A!;KrJ4LH~3h_y_tMAK>5S|49o|DnJGPOaWc) zkNX{7D$mxB*R%R5tF~@%&@V@L`w2i|NAVi&hW%m-uqIm&6&Qa6Tm}Xz@KXg|*oF~o literal 0 HcmV?d00001 diff --git a/V2Code/com/.DS_Store b/V2Code/com/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..88c278cab27b62ed99e34d2dbe948a2ac49c25b5 GIT binary patch literal 6148 zcmeHKJ8r`;3?*9w36RBOM_nN|5RCK$xj@i5=wj4^(cM$e)uZ+CGsJMaxkHLagL)Fh zC&O}Y%BKx$vwicGJ!C|IaGY_KcX{il*WqPcW&a#7?oI|gqfEE_ zaj-2K6`%rCfC^9nDzLEvSzz~vjnCzARDcTHzXEnY6u4ncoCE#pz~C(autC@jbMGa9 z#R9;ZI0qsE)1U%_s@Y;_&=D`0R}<&Jpo?bnq4{Rb4n_U#IKOzhXbt2@1*pJMfyY?3 zR{x*jzx4l05?54!3j8Ytv^kwm9X=^*>+0jI))x2$ZaH6YGt8ZW!OJnw%P|&Kj-Na! b@`}x|UlZp*rz7rkAb$o-7aA4#YX!am(ySGY literal 0 HcmV?d00001 diff --git a/V2Code/com/lloseng/.DS_Store b/V2Code/com/lloseng/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..8021eb503a668590e5c23871c17e3f74e90224f0 GIT binary patch literal 6148 zcmeH~F^-*1l_veYO--;({to>)nK zk%_J(C_q3P^!x@qaLyQ3Az;YPZF-wre3uH~UPF84^(}QKJ z#TerCXeUcvSCg%?x5IMyu)MSR6hpJ#4l7J(Rs#xBKng4r*z|n#^Z!VHHvcbLlu7|9 z@Ma3waQHdw`BHhd{(C*IpR(%fMknKPhKHX3CVmv}=waM1z94I|b+SU!k3h(vAO&8k Fz#q~e60iUO literal 0 HcmV?d00001 diff --git a/V2Code/com/lloseng/ocsf/.DS_Store b/V2Code/com/lloseng/ocsf/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..7ea673f41ba91c863e25121f3b3a265240012173 GIT binary patch literal 6148 zcmeHKK}rKb5bV|F$^Jb+?u~72uxER+ zAAB5$jRS(O_QCP{U~b5yfE17dQa}nwfpZn8N;+Shdw_USKnh%}0{lKSII$OwiSg;c z5G??3hHx0>(Mtdu1HfK5CL#j!qym%b)na(k5pR{(3&+Hyo5#&Kr*8J@P&{r&yhXZs zPt+&{q`;{H*STD>{@=s@=>JbiT1f#Za8U~QZ2hoa;Yn3nCy!&TZSW18IiGME=0U*_ lu;+epg1#yR$T;g}e7#Dfmh&j59iNrC@X;0wxc8;k$| literal 0 HcmV?d00001 diff --git a/code/.DS_Store b/code/.DS_Store index d91f717ee0fef530fe6eae00ddf11ece6c9f642a..49f0478039248d4f631622be9aa6a172cee1af10 100644 GIT binary patch delta 105 zcmZoMXfc@J&&WP8U^gTCWFAIK4R(eChJ1!hhCGH6hGd3Uw#1T4h%*B diff --git a/code/postal/.DS_Store b/code/postal/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..c27bb736a2f551976a524a966d627852786f6e5f GIT binary patch literal 6148 zcmeHKyG{c!5S)b+5ouCV`WN^ED+*u04+L^_Cmm9tzl!hT)0lk}L=8Knh3!DIf(dra+a}_2yzH>L4i~1+GN_|2{OjV=tT&~aIU~@ zF1KF)AL)Pe|K}vFq<|E-Dg|t{f7 " + message); + } + + + //Class methods *************************************************** + + /** + * This method is responsible for the creation of the Client UI. + * + * @param args[0] The host to connect to. + */ + public static void main(String[] args) + { + int port = 0; //The port number + + try + { + port = Integer.parseInt(args[0]); + } + catch(Throwable t) + { + port = DEFAULT_PORT; + } + ServerConsole server= new ServerConsole(port); + server.accept(); //Wait for console data + } +} +//End of ConsoleChat class From 16a19d074bb4956bad3b8cf8e48053e8e444ebc9 Mon Sep 17 00:00:00 2001 From: ShaanBhoi <46392837+ShaanBhoi@users.noreply.github.com> Date: Sun, 14 Jun 2020 05:57:29 -0400 Subject: [PATCH 06/11] Finished E6 & E7, forgot to push after E6, made many changes, will finish up tmr with tests and clean up of code --- code/simplechat1/ClientConsole.java | 12 +- code/simplechat1/EchoServer.java | 242 +++++++++++++++--------- code/simplechat1/ServerConsole.java | 23 +-- code/simplechat1/client/ChatClient.java | 42 ++-- 4 files changed, 195 insertions(+), 124 deletions(-) diff --git a/code/simplechat1/ClientConsole.java b/code/simplechat1/ClientConsole.java index c9bb4e9..41b0235 100644 --- a/code/simplechat1/ClientConsole.java +++ b/code/simplechat1/ClientConsole.java @@ -41,11 +41,11 @@ 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 loginID) { try { - client= new ChatClient(host, port, this); + client= new ChatClient(host, port, this,loginID); } catch(IOException exception) { @@ -105,17 +105,21 @@ public void display(String message) public static void main(String[] args) { String host = ""; + String loginID=""; int port = 0; //The port number try { - host = args[0]; + loginID = args[0]; + host = args[1]; + port = Integer.parseInt(args[2]); } catch(ArrayIndexOutOfBoundsException e) { host = "localhost"; + port = DEFAULT_PORT; } - ClientConsole chat= new ClientConsole(host, DEFAULT_PORT); + ClientConsole chat= new ClientConsole(host,port,loginID); chat.accept(); //Wait for console data } } diff --git a/code/simplechat1/EchoServer.java b/code/simplechat1/EchoServer.java index cc06525..0fa2ba8 100644 --- a/code/simplechat1/EchoServer.java +++ b/code/simplechat1/EchoServer.java @@ -25,8 +25,8 @@ public class EchoServer extends AbstractServer * The default port to listen on. */ final public static int DEFAULT_PORT = 5555; - private boolean serverClosed ; - ChatIF serverUI; + private boolean serverIsOpen = false ; + private ChatIF serverUI; //Constructors **************************************************** @@ -39,9 +39,112 @@ public EchoServer(int port) { super(port); } + public EchoServer(int port,ChatIF serverUI) throws IOException{ + super(port); + this.serverUI = serverUI; + listen(); + } //Instance methods ************************************************ + + /** + * This method handles any messages received from the client. + * + * @param msg The message received from the client. + * @param client The connection from which the message originated. + */ + + public void handleMessageFromClient(Object msg, ConnectionToClient client){ + String mesg = (String)msg; + + if (mesg.contains("#login")){ + String loginID = mesg.substring(7); + client.setInfo("#login",loginID); + System.out.println("> Message received: "+mesg+" from "+client); + System.out.println("> "+loginID+" has logged on."); + } + + else{ + String loginSTR = (String) client.getInfo("#login"); //cast getInfo data to String + System.out.println("> Message received: "+mesg+" from "+loginSTR); + this.sendToAllClients(loginSTR+": "+mesg); + } + } + /* + * + */ + public void handleMessageFromServerUI(String message){ + try{ + if (message.equals("#quit")) { + sendToAllClients("The server is quitting..."); + quit(); + } + + else if (message.equals("#stop")) { + sendToAllClients("The server has stopped listening for new connections..."); + stopListening(); + } + + else if (message.equals("#close")) { + sendToAllClients("Server is shutting down...\nServer will now disconnect..."); + close(); + + } + + else if (message.startsWith("#setport")) { + if (!serverIsOpen) { + int port = Integer.parseInt(message.split("\\s+")[1]); + setPort(port); + } + else{ + serverUI.display("Cant set port"); + } + + + + + + + /* + if (!serverIsOpen) { + serverUI.display("Invalid command\nCannot set port if server is open\nPlease close server with command #close"); + return; + } + try{ + int port = Integer.parseInt(message.split("\\s+")[1]); + setPort(port); + serverUI.display("Port has been set to :"+port); + } + catch(Exception e){ + serverUI.display("Invalid port"); + return; + } + */ + } + + else if (message.equals("#getport")) { + serverUI.display("Port: "+getPort()); + + } + else if (message.equals("#start")) { + listen(); + } + else if (message.startsWith("#")) { + serverUI.display("Invalid command. Please try again.\nPossible commands are:\n#quit\t: to quit the server\n#stop\t: to stop listening for new clients\n#close\t: to stop listening for new clients and disconnect all existing clients\n#start\t: to start the server, only valid if stopped\n#setport\t: to set the port if stopped\n#getport\t: to get the current port"); + } + else{ + sendToAllClients("SERVER MSG >"+message); + } + } + catch(IOException e) + { + serverUI.display + ("Could not send message to all clients. Terminating server."); + quit(); + } + } + /** * Hook method called each time a new client connection is * accepted. The default implementation does nothing. @@ -60,7 +163,11 @@ protected void clientConnected(ConnectionToClient client) { */ synchronized protected void clientDisconnected( ConnectionToClient client) { - System.out.println("A user has disconnected from the server."); + //System.out.println("A user has disconnected from the server."); + + String loginSTR = (String) client.getInfo("#login"); + sendToAllClients("> "+loginSTR+" has disconnected from the server."); + } /** @@ -78,89 +185,9 @@ synchronized protected void clientException( } - /** - * This method handles any messages received from the client. - * - * @param msg The message received from the client. - * @param client The connection from which the message originated. - */ - public void handleMessageFromClient - (Object msg, ConnectionToClient client) - { - System.out.println("Message received: " + msg + " from " + client); - this.sendToAllClients(msg); - } - - /* - * - */ - public void handleMessageFromServerUI(String message){ - if (message.equals("#quit")) { - try{ - System.out.println("The server is quitting..."); - this.close(); - } - - catch(IOException e){ - System.exit(0); - } - } - - else if (message.equals("#stop")) { - System.out.println("The server has stopped listening for new connections..."); - this.stopListening(); - } - - else if (message.equals("#close")) { - try{ - close(); - System.out.println("Server is shutting down...\nServer will now stop listening for new clients..."); - System.out.println("Server is shutting down...\nServer is now shut down..."); - - } - catch(IOException e){ - - } - - } - - else if (message.startsWith("#setport")) { - if (!serverClosed) { - System.out.println("Invalid command\nCannot set port if server is open\nPlease close server with command #close"); - return; - } - try{ - int port = Integer.parseInt(message.split("\\s+")[1]); - setPort(port); - System.out.println("Port has been set to :"+port); - } - catch(Exception e){ - serverUI.display("Invalid port"); - return; - } - } - - else if (message.equals("#getport")) { - serverUI.display("Port: "+getPort()); - - } - else if (message.equals("#start")) { - try{ - this.listen(); - } - catch (Exception e){ - - } - - } - else if (message.startsWith("#")) { - serverUI.display("Invalid command. Please try again.\nPossible commands are:\n#quit\t: to quit the server\n#stop\t: to stop listening for new clients\n#close\t: to stop listening for new clients and disconnect all existing clients\n#start\t: to start the server, only valid if stopped\n#setport\t: to set the port if stopped\n#getport\t: to get the current port"); - } - else{ - sendToAllClients(message); - } + - } + /** * This method overrides the one in the superclass. Called @@ -169,7 +196,7 @@ else if (message.startsWith("#")) { protected void serverStarted() { System.out.println("Server listening for connections on port " + getPort()); - serverClosed = true; + serverIsOpen = true; } /** @@ -180,9 +207,45 @@ protected void serverStopped() { System.out.println ("Server has stopped listening for connections."); - serverClosed = false; + serverIsOpen = false; } - + + /** + * This method overrides the one in the superclass. Called + * when the server stops listening for connections. + */ + public void quit(){ + try{close();} + catch(IOException e){} + System.exit(0); + } + + /** + * This method waits for input from the console. Once it is + * received, it sends it to the client's message handler. + */ + public void accept() + { + try + { + BufferedReader fromConsole = + new BufferedReader(new InputStreamReader(System.in)); + String message; + + while (true) + { + message = fromConsole.readLine(); + handleMessageFromServerUI(message); + } + } + catch (Exception ex) + { + System.out.println + ("Unexpected error while reading from console!"); + } + } + + //Class methods *************************************************** /** @@ -210,7 +273,8 @@ public static void main(String[] args) try { sv.listen(); //Start listening for connections - } + sv.accept(); + } catch (Exception ex) { System.out.println("ERROR - Could not listen for clients!"); diff --git a/code/simplechat1/ServerConsole.java b/code/simplechat1/ServerConsole.java index 63cb86e..34bc8be 100644 --- a/code/simplechat1/ServerConsole.java +++ b/code/simplechat1/ServerConsole.java @@ -30,19 +30,11 @@ public class ServerConsole implements ChatIF{ * @param host The host to connect to. * @param port The port to connect on. */ - public ServerConsole(int port){ - server = new EchoServer(port); - try - { - server.listen(); - } - catch(IOException exception) - { - System.out.println("Error: Couldnt listen for clients"); - System.exit(0); - } + public ServerConsole(int port)throws IOException{ ///////// see pics + server = new EchoServer(port,this); } + //Instance methods ************************************************ @@ -112,7 +104,7 @@ public void display(String message) * * @param args[0] The host to connect to. */ - public static void main(String[] args) + public static void main(String[] args) throws IOException { int port = 0; //The port number @@ -125,7 +117,12 @@ public static void main(String[] args) port = DEFAULT_PORT; } ServerConsole server= new ServerConsole(port); + try{ server.accept(); //Wait for console data + } + catch(Exception ex){ + System.out.println("Could not listen for clients..."); + } } } -//End of ConsoleChat class +//End of ServerConsole class diff --git a/code/simplechat1/client/ChatClient.java b/code/simplechat1/client/ChatClient.java index dc549da..b16988e 100644 --- a/code/simplechat1/client/ChatClient.java +++ b/code/simplechat1/client/ChatClient.java @@ -25,7 +25,8 @@ public class ChatClient extends AbstractClient * The interface type variable. It allows the implementation of * the display method in the client. */ - ChatIF clientUI; + private ChatIF clientUI; + private String loginID = ""; //Constructors **************************************************** @@ -36,14 +37,31 @@ public class ChatClient extends AbstractClient * @param host The server to connect to. * @param port The port number to connect on. * @param clientUI The interface type variable. + * @param loginID The clients loginID */ - public ChatClient(String host, int port, ChatIF clientUI) + public ChatClient(String host, int port, ChatIF clientUI,String loginID) throws IOException { super(host, port); //Call the superclass constructor this.clientUI = clientUI; - openConnection(); + this.loginID = loginID; + + if (loginID.equals("")) { + clientUI.display("No loginID detected\nTerminating connection..."); + quit(); + } + + else{ + try{ + openConnection(); + sendToServer("#login"+loginID); + clientUI.display(loginID+" has logged on"); + } + catch(Exception e){ + clientUI.display("Unable to connect to server\nAwaiting command..."); + } + } } @@ -63,19 +81,6 @@ public void handleMessageFromServer(Object msg) * This method handles all data coming from the UI * * @param message The message from the UI. - - try - { - sendToServer(message); - } - catch(IOException e) - { - clientUI.display - ("Could not send message to server. Terminating client."); - quit(); - } - - */ public void handleMessageFromClientUI(String message){ @@ -86,6 +91,7 @@ public void handleMessageFromClientUI(String message){ else if (message.equals("#logoff")) { try { + clientUI.display("Logging off..."); closeConnection(); } catch (IOException ignored){ @@ -124,7 +130,7 @@ else if (!isConnected()) { try{ int port = Integer.parseInt(message.split("\\s+")[1]); setPort(port); - clientUI.display("Port has been set to: " +port); + clientUI.display("Port has been set to: " +getPort()); } catch(Exception e){ clientUI.display("Invalid port."); @@ -142,7 +148,7 @@ else if (message.equals("#login")) { else if (!isConnected()) { try{ openConnection(); - clientUI.display("Loggin in."); + clientUI.display("Loggin in..."); } catch(IOException e){ clientUI.display("Unable to log in."); From 5b77e543a5bd410fe8ea1b53bcb8eb82dd9c8d90 Mon Sep 17 00:00:00 2001 From: ShaanBhoi <46392837+ShaanBhoi@users.noreply.github.com> Date: Sun, 14 Jun 2020 22:50:53 -0400 Subject: [PATCH 07/11] Added file for phase 2 tests with phase 1 inside of the file unfilled, need to repull original repo to redo phase 1 tests that are in the file PHASE2TestCases and copy/past log info in it --- .DS_Store | Bin 6148 -> 6148 bytes PHASE2TestCases | 827 +++++++++++++++++++++++++++++++++++ V2Code/com/lloseng/.DS_Store | Bin 6148 -> 6148 bytes code/.DS_Store | Bin 6148 -> 6148 bytes 4 files changed, 827 insertions(+) create mode 100644 PHASE2TestCases diff --git a/.DS_Store b/.DS_Store index 5bf02b4b0a498501b704963e443144f872824151..4b6043135b63182d331d2885f9a79e984f7bc8ff 100644 GIT binary patch delta 22 ecmZoMXfc?OF!7-FWCIbFiT#3%3>z0Fivs{�Rec delta 22 ecmZoMXfc?OFmb2$WCIbFiT#3%j2jmwivs{&Q3t31 diff --git a/PHASE2TestCases b/PHASE2TestCases new file mode 100644 index 0000000..b04df5e --- /dev/null +++ b/PHASE2TestCases @@ -0,0 +1,827 @@ +/****************************************** + * Shaan Bhoi * + * 300037516 * + * SEG 2105 Z-[XX] * + * Assignment 01 * + * Univeristy of Ottawa * + ******************************************/ + + + + + + + + + + +test cases for phase 2 have been completed at the end of e7 + +indent tests were not completed due to the fact that i only have access to one computer + + + + + + + + +Testcases - Phase 2 + + +
+GENERAL SETUP FOR TESTCASES
+System: Simple Chat/OCSF           Phase: 2
+
+Instructions:                    
+1. Install JAVA, minimum release 1.2.0, on Windows 95 or 98.
+2. Install JAVA, minimum release 1.2.0, on Windows NT.
+3. Install JAVA, minimum release 1.2.0, on a Solaris system.
+4. Install the Simple Chat - Phase 2 on Windows 95/98, NT and Solaris.
+
+
+Testcase 2001 +System: Simple Chat Phase: 2 to 4 +Server startup check with default arguments +Severity: 1 + +Instructions: +1. At the console, enter: java EchoServer. + +Expected result: +1. The server reports that it is listening for clients by displaying +the following message: + +Server listening for clients on port 5555 + +2. The server console awaits for user input. + +Cleanup: +Hit CTRL+C to kill the server. + +shaanbhoi@ShaanMacBookPro ~ % cd Desktop/SEG_2105_Summer2020_Assignment_1/Lloseng/code +shaanbhoi@ShaanMacBookPro code % javac ocsf/*/*.java +Note: Some input files use or override a deprecated API. +Note: Recompile with -Xlint:deprecation for details. +Note: ocsf/server/ConnectionToClient.java uses unchecked or unsafe operations. +Note: Recompile with -Xlint:unchecked for details. +shaanbhoi@ShaanMacBookPro code % cd simplechat1 +shaanbhoi@ShaanMacBookPro simplechat1 % javac -classpath ../../code *.java client/*.java common/*.java +shaanbhoi@ShaanMacBookPro simplechat1 % java -classpath '../../code:.' EchoServer +Server listening for connections on port 5555 + + + +
+Testcase 2002 +System: Simple Chat Phase: 2 +Client startup check without a login +Severity: 1 + +Instructions: +1. At the console, enter: java ClientConsole. + +Expected result: +1. The client reports it cannot connect without a login by displaying: + +ERROR - No login ID specified. Connection aborted. + +2. The client terminates. + +Cleanup: (if client is still active) +Hit CTRL+C to kill the client. + +Last login: Sun Jun 14 22:09:33 on ttys000 +shaanbhoi@ShaanMacBookPro ~ % cd Desktop/SEG_2105_Summer2020_Assignment_1/Lloseng/code +shaanbhoi@ShaanMacBookPro code % javac ocsf/*/*.java +Note: Some input files use or override a deprecated API. +Note: Recompile with -Xlint:deprecation for details. +Note: ocsf/server/ConnectionToClient.java uses unchecked or unsafe operations. +Note: Recompile with -Xlint:unchecked for details. +shaanbhoi@ShaanMacBookPro code % cd simplechat1 +shaanbhoi@ShaanMacBookPro simplechat1 % javac -classpath ../../code *.java client/*.java common/*.java +shaanbhoi@ShaanMacBookPro simplechat1 % java -classpath '../../code:.' ClientConsole +> No loginID detected +Terminating connection... +> The connection to the server has been closed. +shaanbhoi@ShaanMacBookPro simplechat1 % java -classpath '../../code:.' ClientConsole +> No loginID detected +Terminating connection... +> The connection to the server has been closed. +shaanbhoi@ShaanMacBookPro simplechat1 % + +
+Testcase 2003 +System: Simple Chat Phase: 2 +Client startup check with a login and without a server +Severity: 1 + +Instructions: +1. At the console, enter: java ClientConsole <loginID> where loginID +is the name you wish to be identified by. + +Expected result: +1. The client reports it cannot connect to a server by displaying: + +Cannot open connection. Awaiting command. + +2. The client waits for user input + +Cleanup: +Hit CTRL+C to kill the client. + + +Last login: Sun Jun 14 22:09:37 on ttys001 +shaanbhoi@ShaanMacBookPro ~ % cd Desktop/SEG_2105_Summer2020_Assignment_1/Lloseng/code +shaanbhoi@ShaanMacBookPro code % javac ocsf/*/*.java +Note: Some input files use or override a deprecated API. +Note: Recompile with -Xlint:deprecation for details. +Note: ocsf/server/ConnectionToClient.java uses unchecked or unsafe operations. +Note: Recompile with -Xlint:unchecked for details. +shaanbhoi@ShaanMacBookPro code % cd simplechat1 +shaanbhoi@ShaanMacBookPro simplechat1 % javac -classpath ../../code *.java client/*.java common/*.java +shaanbhoi@ShaanMacBookPro simplechat1 % java -classpath '../../code:.' ClientConsole +> No loginID detected +Terminating connection... +> The connection to the server has been closed. +shaanbhoi@ShaanMacBookPro simplechat1 % java -classpath '../../code:.' ClientConsole 01 +> Unable to connect to server +Awaiting command... + + + +
+Testcase 2004 +System: Simple Chat Phase: 2 +Client connection with default arguments +Severity: 1 + +Instructions: + +1. Start a server (Testcase 2001, instruction 1) + +2. On a different console on the same computer, start a +client (Testcase 2003, instruction 1) + +Expected results: +1. The server displays the following messages in sequence: + +A new client is attempting to connect to the server. +Message received #login <loginID> from null. +<loginID> has logged on. + +hoi@ShaanMacBookPro simplechat1 % java -classpath '../../code:.' EchoServer +Server listening for connections on port 5555 +A new user has connected to the server. +> Message received: #login01 from localhost (127.0.0.1) +> 1 has logged on. + + + +2. The client displays message: + +<loginID> has logged on. + + +shaanbhoi@ShaanMacBookPro simplechat1 % java -classpath '../../code:.' ClientConsole 01 +> The connection to the server has been established. +> 01 has logged on + + + +3. The client and the server wait for user input. + +Cleanup: (unless proceeding to Testcase 2005) +Hit CTRL+C to kill the client. +Hit CTRL+C to kill the server. + + + + + + +
+Testcase 2005 +System: Simple Chat Phase: 2 +Client Data transfer and data echo +Severity: 1 + +Instructions: +1. Start a server and a client on the same computer and connect using +default arguments (Testcase 2004 instructions). + +2. Once connected, type in data on the client console and press ENTER. + +Expected results: +1. The message is echoed on the client side, but is preceded by the +sender's loginID and the greater than symbol(">"). + + +shaanbhoi@ShaanMacBookPro simplechat1 % java -classpath '../../code:.' ClientConsole 01 +> The connection to the server has been established. +> 01 has logged on +hello all +> 1: hello all + + + + +2. The server displays a message similar to the following: + +Message received: <user input> from <loginID> + +shaanbhoi@ShaanMacBookPro simplechat1 % java -classpath '../../code:.' EchoServer +Server listening for connections on port 5555 +A new user has connected to the server. +> Message received: #login01 from localhost (127.0.0.1) +> 1 has logged on. +> Message received: hello all from 1 + +Cleanup: (unless proceeding to Testcase 2006) +Hit CTRL+C to kill the client. +Hit CTRL+C to kill the server. + + + + + +
+Testcase 2006 +System: Simple Chat Phase: 2 +Multiple local connections +Severity: 1 + +Instructions: +1. Start a server and multiple clients with DIFFERENT loginIDs and connect +them to the server using default arguments. (Testcase 2005 instructions). + +2. Start typing on all the client consoles AND the server console, +pressing ENTER to send each message. +shaanbhoi@ShaanMacBookPro simplechat1 % java -classpath '../../code:.' ClientConsole 01 +> The connection to the server has been established. +> 01 has logged on +hello all +> 1: hello all +> 2: hello from 2 +hello from 1 +> 1: hello from 1 +> SERVER MSG >hello from server + +shaanbhoi@ShaanMacBookPro simplechat1 % java -classpath '../../code:.' ClientConsole 02 +> The connection to the server has been established. +> 02 has logged on +hello from 2 +> 2: hello from 2 +> 1: hello from 1 +> SERVER MSG >hello from server + + + + +shaanbhoi@ShaanMacBookPro simplechat1 % java -classpath '../../code:.' EchoServer +Server listening for connections on port 5555 +A new user has connected to the server. +> Message received: #login01 from localhost (127.0.0.1) +> 1 has logged on. +> Message received: hello all from 1 +A new user has connected to the server. +> Message received: #login02 from localhost (127.0.0.1) +> 2 has logged on. +> Message received: hello from 2 from 2 +> Message received: hello from 1 from 1 +hello from server + + + +Expected results: +1. All client messages are echoed as in Testcase 2005. + +2. All messages from the server console are echoed on the server console +and to all clients, but are preceeded by "SERVER MESSAGE> ". + +Cleanup: +Hit CTRL+C to kill the clients +Hit CTRL+C to kill the servers + + + + + + + + +
+Testcase 2007 +System: Simple Chat Phase: 2 and subsequent +Server termination command check +Severity: 1 + +Instructions: +1. Start a server (Testcase 2001 instruction 1) using default arguments. + +2. Type "#quit" into the server's console. + +Expected result: +1. The server quits. + + +#quit +Server has stopped listening for connections. +shaanbhoi@ShaanMacBookPro simplechat1 % + + + + +Cleanup (If the server is still active): +Hit CTRL+C to kill the server. + +
+Testcase 2008 +System: Simple Chat Phase: 2 and 3 +Server stop check +Severity: 2 + +Instructions: +1. Start a server (Testcase 1001, instruction 1). + +2. Connect a client to the server (Testcase 2004). + +3. Type "#stop" into the server's console. + +4. Type in a message on the client and send it. + +5. Attempt to connect other clients. + +6. Restart the server. + +Expected results: +1. The server displays: + +Server has stopped listening for connections. + +2. The client displays: + +WARNING - Server has stopped listening for connections. + +3. Data echoing still works normally. + +4. Attempting to connect other clients will hang the console as these new +connections are put on backlog until the max backlog (default of 10) is reached. + +5. Restarting the server will cause the backlogged clients to connect properly. + +shaanbhoi@ShaanMacBookPro simplechat1 % java -classpath '../../code:.' EchoServer +Server listening for connections on port 5555 +A new user has connected to the server. +> Message received: #login01 from localhost (127.0.0.1) +> 1 has logged on. +#stop +Server has stopped listening for connections. +> Message received: hey from 1 +#start +Server listening for connections on port 5555 +A new user has connected to the server. +> Message received: #login02 from localhost (127.0.0.1) +> 2 has logged on. + + + + +shaanbhoi@ShaanMacBookPro simplechat1 % java -classpath '../../code:.' ClientConsole 01 +> The connection to the server has been established. +> 01 has logged on +> The server has stopped listening for new connections... +hey +> 1: hey + +shaanbhoi@ShaanMacBookPro simplechat1 % java -classpath '../../code:.' ClientConsole 02 +> The connection to the server has been established. +> 02 has logged on + + + + +Cleanup: (Unless proceeding to Testcase 2008) +Type #quit to kill the server +Hit CTRL+C to kill the client + +
+Testcase 2009 +System: Simple Chat Phase: 2 and 3 +Server close command check +Severity: 2 + +Instructions: +1. Start a server and connect a client to it. (Testcase 2007 instruction 1) + +2. Stop the server using the #stop command. + +3. Type "#close" into the server's console. + +Expected result: +1. Server displays in sequence: + +Server has stopped listening for connections. +<loginID> has disconnected. + +shaanbhoi@ShaanMacBookPro simplechat1 % java -classpath '../../code:.' EchoServer +Server listening for connections on port 5555 +A new user has connected to the server. +> Message received: #login01 from localhost (127.0.0.1) +> 1 has logged on. +#stop +Server has stopped listening for connections. +#close + + + +2. The client displays: + +WARNING - The server has stopped listening for connections +SERVER SHUTTING DOWN! DISCONNECTING! +Abnormal termination of connection. + +and then waits for input. +shaanbhoi@ShaanMacBookPro simplechat1 % java -classpath '../../code:.' ClientConsole 01 +> The connection to the server has been established. +> 01 has logged on +> The server has stopped listening for new connections... +> Server is shutting down... +Server will now disconnect... +> The server has shut down. +Quitting... +> The connection to the server has been closed. +Cleanup: (Unless proceeding to Testcase 2009) +Hit CTRL+C to kill the client. +Hit CTRL+C to kill the server. + +
+Testcase 2009 +System: Simple Chat Phase: 2 and subsequent +Server restart +Severity: 1 + +Instructions: +1. Start a server, connect a client, and close the server. (Testcase 2008) + +2. Type "#start" into the server's console. + +3. Attempt to connect a client. + +Expected result: +1. The server closes, restarts and then displays: + +Server listening for connections on port 5555. + +shaanbhoi@ShaanMacBookPro simplechat1 % java -classpath '../../code:.' EchoServer +Server listening for connections on port 5555 +A new user has connected to the server. +> Message received: #login01 from localhost (127.0.0.1) +> 1 has logged on. +#close +Server has stopped listening for connections. +#start +Server listening for connections on port 5555 +A new user has connected to the server. +> Message received: #login01 from localhost (127.0.0.1) +> 1 has logged on. + + + +2. The client connects normally as described in Testcase 2004. +shaanbhoi@ShaanMacBookPro simplechat1 % java -classpath '../../code:.' ClientConsole 01 +> The connection to the server has been established. +> 01 has logged on +> Server is shutting down... +Server will now disconnect... +> The server has shut down. +Quitting... +> The connection to the server has been closed. +shaanbhoi@ShaanMacBookPro simplechat1 % java -classpath '../../code:.' ClientConsole 01 +> The connection to the server has been established. +> 01 has logged on + + +Cleanup: (Unless proceeding to Testcase 2010) +Hit CTRL+C to kill the client. +Type #quit to kill the server. + +
+Testcase 2010 +System: Simple Chat Phase: 2 and subsequent +Client termination command check +Severity: 1 + +Instructions: +1. Start a client (Testcase 2002, instruction 1). + +2. Type "#quit" into the client's console. + +Expected result: +1. Client terminates. +shaanbhoi@ShaanMacBookPro simplechat1 % java -classpath '../../code:.' ClientConsole 01 +> The connection to the server has been established. +> 01 has logged on +#quit +> Quitting... +> The connection to the server has been closed. +shaanbhoi@ShaanMacBookPro simplechat1 % + +Cleanup: (If client is still active) +Hit CTRL+C to kill the client. + +
+Testcase 2011 +System: Simple Chat Phase: 2 and subsequent +Client logoff check +Severity: 1 + +Instructions: +1. Start a server (Testcase 1001, instruction 1), and then connect a +single local client to this server. + +2. Type "#logoff" into this client's console. + +Expected results: +1. Client disconnects and displays + +Connection closed. (Under NT, it will display +Abnormal termination of connection.) + + +shaanbhoi@ShaanMacBookPro simplechat1 % java -classpath '../../code:.' ClientConsole 01 +> The connection to the server has been established. +> 01 has logged on +#logoff +> Logging off... +> The connection to the server has been closed. +#logoff + + +Cleanup: (Unless proceeding to Testcase 2012) +Type "#quit" to kill the client. + +
+Testcase 2012 +System: Simple Chat Phase: 2 and subsequent +Client host and port setup commands check +Severity: 1 + +Instructions: +1. Start a client but no servers, and attempt to connect using default +arguments. + +2. At the client's console, type +"#sethost <newhost>" +where <newhost> is the name of a computer on the network + + +#sethost ShaanMacBookPro +> Host server has been set to: ShaanMacBookPro + + +3. At the client's console, type +"#setport 1234". + +Expected result: +1. The client displays + +Host set to: <newhost> +port set to: 1234. + + +#setport 1234 +> Port has been set to: 1234 + + +Cleanup: +Type #quit to kill the client. + +
+Testcase 2013 +System: Simple Chat Phase: 2 and subsequent +Starting a server on a non-default port +Severity: 1 + +Instructions: +1. Start a server by typing java ServerConsole 1234. + +Expected result: +1. The server displays + +Server listening for connections on port 1234. + + +shaanbhoi@ShaanMacBookPro simplechat1 % java -classpath '../../code:.' EchoServer 1234 +Server listening for connections on port 1234 + + +Cleanup (Unless proceeding to Testcase 2014) +Type #quit to kill the server. + +
+ Testcase 2014 + System: Simple Chat Phase: 2 and subsequent + Connecting a client to a non-default host or port + Severity: 1 + + Instructions: + 1. Start a server on port 1234 (Testcase 2013) + + 2. On a different computer, start a client by typing + "java ClientConsole <loginID> <host> 1234" + replacing the parameters by appropriate values. + + Expected Result: + 1. The connection occurs normally. + +
+ Testcase 2015 + System: Simple Chat Phase: 2 + Multiple remote clients disconnections and reconnections + Severity: 1 + + Instructions: + 1. Start a server (Testcase 2001, instruction 1). + + 2. On different computers, start clients (1 or 2 per computer) and connect + them to the server. + + 3. Exchange data. + + 4. Close the server using the #close command. + + 5. Change the server's port by typing + "#setport <newport>" + + 6. Restart the server using the #start command. + + 7. Change the ports of each clients using the #setport command. + + 8. Reconnect the clients to the server by using the #login <loginID> + command. + + 9. close the server by using the #quit command. + + Expected results: + 1. The first set of connections occur normally. + + 2. When the server is closed, all clients are disconnected. + + 3. The server displays the following message when the #setport command + is used: + + port set to: <newport>. + + 4. The server restarts and displays: + + Server listening for connections on port <newport>. + + 5. The clients change port as in Testcase 2012. + + 6. The clients reconnect normally. + + 7. The clients are disconnected when the server quits. + + Cleanup: + Type #quit to kill the clients + Type #quit to kill the server (if still active) + +
+ Testcase 2016 + System: Simple Chat Phase: 2 and subsequent + Client changing hosts + Severity: 1 + + Instructions: + 1. On two different computers, start servers on the default port. + + 2. On a third computer, start a client and connect it to one of the + two servers. + + 3. Logoff from that server using the #logoff command. + + 4. Change the host name by using the #sethost <otherhost> + where <otherhost> is the name of the other computer on the network + + 5. Log on to this new host using the #login <loginID> command. + + Expected results: + 1. The two servers start up normally. + + 2. The client connects to the first server normally. + + 3. When the client disconnects it displays + + Connection closed. (Exception: NT will display Abnormal termination of + connection) + + 4. When the client disconnects, the server displays: + + <loginID> has disconnected. + + 5. The client changes host as in Testcase 2012. + + 6. The client reconnects normally as in Testcase 2015. + + Cleanup (Unless proceeding to Testcase 2017): + Type #quit to kill the servers (if proceeding, kill only the one with no + connected clients) + Type #quit to kill the client + +
+Testcase 2017 +System: Simple Chat Phase: 2 and subsequent +Client quitting or logging off a server with multiple connections +Severity: 1 + +Instructions: +1. Start a server and connect multiple (at least 3) clients. + +2. In one client's console, type "#quit". + +3. In a second client's console type "#logoff". + +Expected results: +1. In both cases, all remaining clients and the server get the following +message: + +<loginID> has disconnected. + +2. The clients display: + +Connection Closed. (Exception: NT will display "Abnormal termination of +connection." when the logoff command is used.) + +shaanbhoi@ShaanMacBookPro simplechat1 % java -classpath '../../code:.' EchoServer +Server listening for connections on port 5555 +A new user has connected to the server. +> Message received: #login01 from localhost (127.0.0.1) +> 1 has logged on. +A new user has connected to the server. +> Message received: #login02 from localhost (127.0.0.1) +> 2 has logged on. +A new user has connected to the server. +> Message received: #login03 from localhost (127.0.0.1) +> 3 has logged on. + + + + +> No loginID detected +Terminating connection... +> The connection to the server has been closed. +shaanbhoi@ShaanMacBookPro simplechat1 % java -classpath '../../code:.' ClientConsole 01 +> The connection to the server has been established. +> 01 has logged on +#quit +> Quitting... +> The connection to the server has been closed. +shaanbhoi@ShaanMacBookPro simplechat1 % + +shaanbhoi@ShaanMacBookPro simplechat1 % java -classpath '../../code:.' ClientConsole 02 +> The connection to the server has been established. +> 02 has logged on +> > 1 has disconnected from the server. +#logoff +> Logging off... +> The connection to the server has been closed. + +shaanbhoi@ShaanMacBookPro simplechat1 % java -classpath '../../code:.' ClientConsole 03 +> The connection to the server has been established. +> 03 has logged on +> > 1 has disconnected from the server. +> > 2 has disconnected from the server. + + + + + +
+ Testcase 2018 + System: Simple Chat Phase: 2 + Different platform tests + Severity: 1 + + Instructions: + 1. Repeat all these tests on different platforms (95/98, NT, UNIX). + + Expected results: + 1. The same as before. + +
+ Testcase 2019 + System: Simple Chat Phase: 2 + Interaction between different platforms + Severity: 1 + + Instructions: + 1. Repeat Testcases 2005, 2009, 2010-2019 mixing the platforms involved. + + Expected results: + 1. The same as before. + +
+ + + diff --git a/V2Code/com/lloseng/.DS_Store b/V2Code/com/lloseng/.DS_Store index 8021eb503a668590e5c23871c17e3f74e90224f0..ead42f8652432a7eaf13d008d64d8fac45b0dc11 100644 GIT binary patch delta 24 gcmZoMXfc@Jz{oJsQGR3MGWN;(BCMOaIezj30ARHTlK=n! delta 17 YcmZoMXfc@Jz{oh!QJ#@;W8z|Q04?7H`Tzg` diff --git a/code/.DS_Store b/code/.DS_Store index 49f0478039248d4f631622be9aa6a172cee1af10..c7c9d7ddb9a96ab194e45162eacc9a588f9debf5 100644 GIT binary patch delta 84 zcmZoMXfc?OF!>?l>dD-UqKpia6&V#|7=VDCp@1QuA(J7Gp@bosp&+F=IVUMUKZjv* hETaTaSs9}ekemr7_b^Ire#ofCHnD(vGdss$egKi_76AYN delta 83 zcmZoMXfc?Oz{of;aX%yDWJN{=8Ab*M26l!5hJ1!hhCGH6hGd3uga h5 Date: Sun, 14 Jun 2020 22:59:59 -0400 Subject: [PATCH 08/11] Update to Phase 2 test file reformatted nameplate and aded specificity for cases I can't complete tests for --- PHASE2TestCases | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/PHASE2TestCases b/PHASE2TestCases index b04df5e..e4d22ae 100644 --- a/PHASE2TestCases +++ b/PHASE2TestCases @@ -1,7 +1,8 @@ /****************************************** - * Shaan Bhoi * - * 300037516 * - * SEG 2105 Z-[XX] * + * Shaan Bhoi * + * 300037516 * + * SEG 2105 Z-[XX] * + * sbhoi021@uottawa.ca * * Assignment 01 * * Univeristy of Ottawa * ******************************************/ @@ -14,10 +15,9 @@ - test cases for phase 2 have been completed at the end of e7 -indent tests were not completed due to the fact that i only have access to one computer +indent tests were not completed due to the fact that i only have access to one computer (2014,2015,2016,2018) From b477edc094cdccd18b2db305d8fa7c44dae0682d Mon Sep 17 00:00:00 2001 From: Shaan Bhoi <46392837+ShaanBhoi@users.noreply.github.com> Date: Sun, 14 Jun 2020 23:18:55 -0400 Subject: [PATCH 09/11] added phas1 test cases same as phase 2 cases but for phase 1 --- PHASE1TestCases.html | 539 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 539 insertions(+) create mode 100644 PHASE1TestCases.html diff --git a/PHASE1TestCases.html b/PHASE1TestCases.html new file mode 100644 index 0000000..485746a --- /dev/null +++ b/PHASE1TestCases.html @@ -0,0 +1,539 @@ +/****************************************** + * Shaan Bhoi * + * 300037516 * + * SEG 2105 Z-[XX] * + * sbhoi021@uottawa.ca * + * Assignment 01 * + * Univeristy of Ottawa * + ******************************************/ + + + + + + + + + + +test cases for phase 1 have been completed at the end of e3 + +indent tests were not completed due to the fact that i only have access to one computer (1008,1009,1010,1011,1012,1014,1015,1016) + + + + + +Testcases - Phase 1 + + +
+GENERAL SETUP FOR TESTCASES
+System: Simple Chat/OCSF           Phase: 1
+
+Instructions:                    
+
+1. Install JAVA, minimum release 1.2.0, on Windows 95 or 98, if it is not
+already installed. 
+
+2. Install JAVA, minimum release 1.2.0, on Windows NT, if it is not
+already installed. 
+
+3. Install JAVA, minimum release 1.2.0, on a Solaris system, if it is not
+already installed. 
+
+4. Install the Simple Chat on Windows 95/98, NT and Solaris if it is not
+already installed. 
+
+
+Testcase 1001 +System: Simple Chat Phase: 1 +Server startup check +Severity: 1 + +Instructions: +1. At the console, enter: java EchoServer. + + +shaanbhoi@ShaanMacBookPro ~ % cd Desktop/SEG_2105_Summer2020_Assignment_1/Lloseng/code +shaanbhoi@ShaanMacBookPro code % javac ocsf/*/*.java +cd simplechat1Note: Some input files use or override a deprecated API. +Note: Recompile with -Xlint:deprecation for details. +Note: ocsf/server/ConnectionToClient.java uses unchecked or unsafe operations. +Note: Recompile with -Xlint:unchecked for details. +shaanbhoi@ShaanMacBookPro code % cd simplechat1 +shaanbhoi@ShaanMacBookPro simplechat1 % javac -classpath ../../code *.java client/*.java common/*.java +shaanbhoi@ShaanMacBookPro simplechat1 % java -classpath '../../code:.' EchoServer +Server listening for connections on port 5555 + + +Expected result: +1. The server reports that it is listening for clients by displaying the +following message: Server listening for clients on port 5555 + +Cleanup: +Hit CTRL+C to kill the server. + +
+Testcase 1002 +System: Simple Chat Phase: 1 +Client startup check without a server +Severity: 1 + +Instructions: +1. At the console, enter: java ClientConsole. + +Expected result: +1. The client reports it cannot connect by displaying message: +Error: Can't setup connection! Terminating client. + +shaanbhoi@ShaanMacBookPro ~ % cd Desktop/SEG_2105_Summer2020_Assignment_1/Lloseng/code +shaanbhoi@ShaanMacBookPro code % javac ocsf/*/*.java +cd simplechat1Note: Some input files use or override a deprecated API. +Note: Recompile with -Xlint:deprecation for details. +Note: ocsf/server/ConnectionToClient.java uses unchecked or unsafe operations. +Note: Recompile with -Xlint:unchecked for details. +shaanbhoi@ShaanMacBookPro code % cd simplechat1 +shaanbhoi@ShaanMacBookPro simplechat1 % javac -classpath ../../code *.java client/*.java common/*.java +shaanbhoi@ShaanMacBookPro simplechat1 % java -classpath '../../code:.' ClientConsole +Error: Can't setup connection! Terminating client. +shaanbhoi@ShaanMacBookPro simplechat1 % + + + +2. The client terminates. + +Cleanup: (if client is still active) +Hit CTRL+C to kill the client. + +
+Testcase 1003 +System: Simple Chat Phase: 1 +Client connection with default arguments +Severity: 1 + +Instructions: + +1. Start a server (Testcase 1001, instruction 1) + +2. On a different console on the same computer, start a client (Testcase +1002, instruction 1) + +Expected results: +1. The client displays no message and waits for user input. + + +shaanbhoi@ShaanMacBookPro simplechat1 % javac -classpath ../../code *.java client/*.java common/*.java +shaanbhoi@ShaanMacBookPro simplechat1 % java -classpath '../../code:.' ClientConsole + + + +2. The server displays no message. + + +shaanbhoi@ShaanMacBookPro simplechat1 % javac -classpath ../../code *.java client/*.java common/*.java +shaanbhoi@ShaanMacBookPro simplechat1 % java -classpath '../../code:.' EchoServer +Server listening for connections on port 5555 + + +Cleanup: (unless proceeding to Testcase 1004) +Hit CTRL+C to kill the client. +Hit CTRL+C to kill the server. + +
+Testcase 1004 +System: Simple Chat Phase: 1 +Data transfer and data echo +Severity: 1 + +Instructions: + +1. Start a client and a server on the same computer and connect using +default arguments (Testcase 1003, instruction 1) + +2. When the client is waiting type something into its console and press ENTER. + +Expected results: + +1. The message is echoed on the client side, but is preceded by a greater +than symbol (">"). + +t/*.java common/*.java +shaanbhoi@ShaanMacBookPro simplechat1 % java -classpath '../../code:.' ClientConsole +hello server +> hello server + + + + + + +2. The server displays a message similar to the following: +Message received: <user input> from localhost(127.0.0.1) + + +shaanbhoi@ShaanMacBookPro simplechat1 % java -classpath '../../code:.' EchoServer +Server listening for connections on port 5555 +Message received: hello server from localhost (127.0.0.1) + + + + + +Cleanup: (unless proceeding to Testcase 1005) +Hit CTRL+C to kill the client. +Hit CTRL+C to kill the server. + +
+Testcase 1005 +System: Simple Chat Phase: 1 +Server termination check +Severity: 1 + +Instructions: + +1. Start a server and a client on the same computer and connect using the +default arguments (Testcase 1003, instruction 1). + +2. Kill the server by pressing CTRL+C. + +Expected result: + +1. The client waits for input. Upon receiving input, the client displays +the message "> Could not send message to server. Terminating client." + + +shaanbhoi@ShaanMacBookPro simplechat1 % java -classpath '../../code:.' ClientConsole +sdf +> Could not send message to server. Terminating client. +shaanbhoi@ShaanMacBookPro simplechat1 % + + +2. The clients exits. + +Cleanup: +Hit CTRL+C to kill the client. + +
+Testcase 1006 +System: Simple Chat Phase: 1 +Client termination check +Severity: 1 + +Instructions: + +1. Start a client and a server on the same computer and connect using the +default arguments (Testcase 1003, instruction 1). + +shaanbhoi@ShaanMacBookPro simplechat1 % +shaanbhoi@ShaanMacBookPro simplechat1 % java -classpath '../../code:.' EchoServer +Server listening for connections on port 5555 + +shaanbhoi@ShaanMacBookPro simplechat1 % java -classpath '../../code:.' ClientConsole +^C% shaanbhoi@ShaanMacBookPro simplechat1 % +shaanbhoi@ShaanMacBookPro simplechat1 % + +2. Kill the client by pressing CTRL+C. + + + +3. Start another client using the default arguments. + +t/*.java common/*.java +shaanbhoi@ShaanMacBookPro simplechat1 % java -classpath '../../code:.' ClientConsole +dfg +> dfg + + + +Expected result: + +1. The server does not display any message regarding the disconnection, +and then accepts the second connection. + +Cleanup: (unless proceeding to Testcase 1008) +Hit CTRL+C to kill the server. + +
+Testcase 1007 +System: Simple Chat Phase: 1 +Multiple client connections and data transfer +Severity: 1 + +Instructions: +1. Start a server (Testcase 1001, instruction 1). + +^C% shaanbhoi@ShaanMacBookPro simplechat1 % java -classpath '../../code:.' EchoServer +Server listening for connections on port 5555 +Message received: hi from 1 from localhost (127.0.0.1) +Message received: hey from 2 from localhost (127.0.0.1) +Message received: hello from 3 from localhost (127.0.0.1) +Message received: sup from 4 from localhost (127.0.0.1) + + + +2. On a different console start a client and connect to the server using +default arguments (Testcase 1003, instruction 1). + +shaanbhoi@ShaanMacBookPro simplechat1 % +shaanbhoi@ShaanMacBookPro simplechat1 % java -classpath '../../code:.' ClientConsole +hi from 1 +> hi from 1 +> hey from 2 +> hello from 3 +> sup from 4 + +shaanbhoi@ShaanMacBookPro simplechat1 % java -classpath '../../code:.' ClientConsole +> hi from 1 +hey from 2 +> hey from 2 +> hello from 3 +> sup from 4 + + + + + + +3. Repeat instruction 2 at least 2 more times. + +4. Type in data on any of the consoles and press ENTER. + +Expected results: +1. Each client connects properly. + +2. Every message typed into any one of the consoles is echoed on all of +the client consoles and the server console in the same way as in Testcase +1004. + +Cleanup: (Unless proceeding to Testcase 1009) +Hit CTRL+C to kill the server +Hit CTRL+C to kill the clients + +
+ Testcase 1008 + System: Simple Chat Phase: 1 + Remote connection + Severity: 1 + + Instructions: + 1. Start a server (Testcase 1001, instruction 1). + + 2. On a different computer's console type java ClientConsole + where hostname is the name by which the computer running the server is + identified on the network. The client and server computers should be + running the same OS. + + Expected result: + 1. Connection occurs as in Testcase 1003. + + Cleanup: (Unless proceeding to Testcase 1010) + Hit CTRL+C to kill the client. + Hit CTRL+C to kill the server. + +
+ Testcase 1009 + System: Simple Chat Phase: 1 + Data transfer to a remote connection + Severity: 1 + + Instructions: + 1. Start a server (Testcase 1001, instruction 1). + + 2. Start a remote connection (Testcase 1009, instruction 2). + + 3. Type data into the client console and press ENTER. + + Expected result: + 1. The connection occurs as in Testcase 1003. + + 2. Any data typed is echoed as in Testcase 1004. + + Cleanup: (Unless proceeding to Testcase 1011) + Hit CTRL+C to kill the client. + Hit CTRL+C to kill the server. + +
+ Testcase 1010 + System: Simple Chat Phase: 1 + Multiple remote connections + Severity: 1 + + Instructions: + 1. Start a server (Testcase 1001, instruction 1). + + 2. Start a remote connection (Testcase 1009, instruction 2). + + 3. Repeat instruction 2 from different computers. + + Expected result: + 1. Connections occur as in Testcase 1003. + + Cleanup: (Unless proceeding to Testcase 1012) + Hit CTRL+C to kill the clients. + Hit CTRL+C to kill the server. + +
+ Testcase 1011 + System: Simple Chat Phase: 1 + Data transfer to multiple remote connections + Severity: 1 + + Instructions: + 1. Start a server (Testcase 1001, instruction 1). + + 2. Start a remote connection (Testcase 1009, instruction 2). + + 3. Repeat instruction 2 from different computers. + + 4. Type data on different consoles and press ENTER. + + Expected results: + 1. Connections occur as in Testcase 1003. + + 2. Any data typed in is echoed to all the clients as in Testcase 1004. + + 3. The server displays messages similar to the ones in Testcase 1004. + + Cleanup: (Unless proceeding to Testcase 1013) + Hit CTRL+C to kill the clients. + Hit CTRL+C to kill the server. + +
+ Testcase 1012 + System: Simple Chat Phase: 1 + Server terminating with multiple remote clients + Severity: 1 + + Instructions: + 1. Start a server (Testcase 1001, instruction 1). + + 2. Start a remote connection (Testcase 1009, instruction 2). + + 3. Repeat instruction 2 from different computers. + + 4. Once connections are established, kill the server by hitting CTRL+C. + + Expected result: + 1. All clients behave the same way as expected in Testcase 1005. + + Cleanup: + Hit CTRL+C to kill each client. + +
+Testcase 1013 +System: Simple Chat Phase: 1 +Server terminating with multiple local clients +Severity: 1 + +Instructions: +1. Start a server (Testcase 1001, instruction 1). + +2. On a different console on the same computer start a Client and connect +using default arguments (Testcase 1003, instruction 1). + +3. Repeat instruction 2 a few times. + +4. Once connections are established, kill the server by hitting CTRL+C. + +Expected result: +1. All clients behave the same way as expected in Testcase 1005. + +shaanbhoi@ShaanMacBookPro simplechat1 % java -classpath '../../code:.' ClientConsole + +> Could not send message to server. Terminating client. +shaanbhoi@ShaanMacBookPro simplechat1 % + +shaanbhoi@ShaanMacBookPro simplechat1 % java -classpath '../../code:.' ClientConsole + +> Could not send message to server. Terminating client. +shaanbhoi@ShaanMacBookPro simplechat1 % + +shaanbhoi@ShaanMacBookPro simplechat1 % java -classpath '../../code:.' ClientConsole + +> Could not send message to server. Terminating client. +shaanbhoi@ShaanMacBookPro simplechat1 % + +shaanbhoi@ShaanMacBookPro simplechat1 % java -classpath '../../code:.' ClientConsole + +> Could not send message to server. Terminating client. +shaanbhoi@ShaanMacBookPro simplechat1 % + + +Cleanup: +Hit CTRL+C to kill each client. + +
+ Testcase 1014 + System: Simple Chat Phase: 1 + Other platform checks + Severity: 1 + + Instructions: + + 1. Repeat all the above testcases under other platforms. Use only one + platform for each test, e.g. do not use a unix machine for the client and + an NT machine for the server. + + Expected Result: + 1. Same behaviour as all of the above testcases. + +
+ Testcase 1015 + System: Simple Chat Phase: 1 + Different platforms for the client and servers + Severity: 1 + + Instructions: + 1. Start a server (Testcase 1001, instruction 1). + + 2. On a computer running a different OS, connect to that server (Testcase + 1009, instruction 2). + + 3. Exchange data. + + 4. Repeat instructions 2 and 3, switching operating systems at random. + + 5. Kill any client. + + 6. Kill the server. + + Expected results: + 1. All connections occur the same way as in Testcase 1003. + + 2. All messages are echoed the same way as expected in Testcase 1004. + + 3. All messages are displayed on the server console using the same format + as Testcase 1004. + + 4. Killing a client has the same effect on all clients and the server as + in Testcase 1007. + + 5. Killing the server has the same effect on all clients as in Testcase + 1005. + + Cleanup: + 1. Hit CTRL+C to kill any remaining clients. + +
+ Testcase 1016 + System: Simple Chat Phase: 1 + Severity: 1 + + Instructions: + 1. Repeat Testcase 1015 altering the server OS. + + Expected results: + 1. Same as Testcase 1015. + + Cleanup: + 1. Hit CTRL+C to kill any remaining clients. +
+ + + + + + + + From 0c734e658643af013cdf79a1f8947c0d5fec6d8e Mon Sep 17 00:00:00 2001 From: Shaan Bhoi <46392837+ShaanBhoi@users.noreply.github.com> Date: Sun, 14 Jun 2020 23:20:17 -0400 Subject: [PATCH 10/11] renamed file --- PHASE1TestCases.html => PHASE1TestCases | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename PHASE1TestCases.html => PHASE1TestCases (100%) diff --git a/PHASE1TestCases.html b/PHASE1TestCases similarity index 100% rename from PHASE1TestCases.html rename to PHASE1TestCases From ff0aaada41f870b17c38ec0e577f5fe12bef0dee Mon Sep 17 00:00:00 2001 From: Shaan Bhoi <46392837+ShaanBhoi@users.noreply.github.com> Date: Sun, 14 Jun 2020 23:21:57 -0400 Subject: [PATCH 11/11] added file for terminal commands to copy paste --- notes for commands | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 notes for commands diff --git a/notes for commands b/notes for commands new file mode 100644 index 0000000..cb9e41a --- /dev/null +++ b/notes for commands @@ -0,0 +1,13 @@ +notes for commands + +cd Desktop/SEG_2105_Summer2020_Assignment_1/Lloseng/code + +javac ocsf/*/*.java + +cd simplechat1 + + +javac -classpath ../../code *.java client/*.java common/*.java +________________________________________________ +java -classpath '../../code:.' EchoServer +java -classpath '../../code:.' ClientConsole \ No newline at end of file