diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..4b60431 Binary files /dev/null and b/.DS_Store differ diff --git a/PHASE1TestCases b/PHASE1TestCases new file mode 100644 index 0000000..485746a --- /dev/null +++ b/PHASE1TestCases @@ -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. +
+ + + + + + + + diff --git a/PHASE2TestCases b/PHASE2TestCases new file mode 100644 index 0000000..e4d22ae --- /dev/null +++ b/PHASE2TestCases @@ -0,0 +1,827 @@ +/****************************************** + * Shaan Bhoi * + * 300037516 * + * SEG 2105 Z-[XX] * + * sbhoi021@uottawa.ca * + * 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 (2014,2015,2016,2018) + + + + + + + + +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/.DS_Store b/V2Code/.DS_Store new file mode 100644 index 0000000..35a54bf Binary files /dev/null and b/V2Code/.DS_Store differ diff --git a/V2Code/com/.DS_Store b/V2Code/com/.DS_Store new file mode 100644 index 0000000..88c278c Binary files /dev/null and b/V2Code/com/.DS_Store differ diff --git a/V2Code/com/lloseng/.DS_Store b/V2Code/com/lloseng/.DS_Store new file mode 100644 index 0000000..ead42f8 Binary files /dev/null and b/V2Code/com/lloseng/.DS_Store differ diff --git a/V2Code/com/lloseng/ocsf/.DS_Store b/V2Code/com/lloseng/ocsf/.DS_Store new file mode 100644 index 0000000..7ea673f Binary files /dev/null and b/V2Code/com/lloseng/ocsf/.DS_Store differ diff --git a/code/.DS_Store b/code/.DS_Store new file mode 100644 index 0000000..c7c9d7d Binary files /dev/null and b/code/.DS_Store differ diff --git a/code/ocsf/.DS_Store b/code/ocsf/.DS_Store new file mode 100644 index 0000000..7ea673f Binary files /dev/null and b/code/ocsf/.DS_Store differ diff --git a/code/postal/.DS_Store b/code/postal/.DS_Store new file mode 100644 index 0000000..c27bb73 Binary files /dev/null and b/code/postal/.DS_Store differ diff --git a/code/simplechat1/.DS_Store b/code/simplechat1/.DS_Store new file mode 100644 index 0000000..b3aefda Binary files /dev/null and b/code/simplechat1/.DS_Store differ 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 d4f3a1a..0fa2ba8 100644 --- a/code/simplechat1/EchoServer.java +++ b/code/simplechat1/EchoServer.java @@ -1,9 +1,11 @@ +// 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 import java.io.*; import ocsf.server.*; +import common.*; /** * This class overrides some of the methods in the abstract @@ -23,6 +25,8 @@ public class EchoServer extends AbstractServer * The default port to listen on. */ final public static int DEFAULT_PORT = 5555; + private boolean serverIsOpen = false ; + private ChatIF serverUI; //Constructors **************************************************** @@ -35,22 +39,155 @@ 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) - { - System.out.println("Message received: " + msg + " from " + client); - this.sendToAllClients(msg); + + 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. + * @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."); + + String loginSTR = (String) client.getInfo("#login"); + sendToAllClients("> "+loginSTR+" 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 overrides the one in the superclass. Called @@ -58,8 +195,8 @@ public EchoServer(int port) */ protected void serverStarted() { - System.out.println - ("Server listening for connections on port " + getPort()); + System.out.println("Server listening for connections on port " + getPort()); + serverIsOpen = true; } /** @@ -70,8 +207,45 @@ protected void serverStopped() { System.out.println ("Server has stopped listening for connections."); + 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 *************************************************** /** @@ -99,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 new file mode 100644 index 0000000..34bc8be --- /dev/null +++ b/code/simplechat1/ServerConsole.java @@ -0,0 +1,128 @@ +//ServerConsole.java + +//Similar to ClientConsole, but with modification to allow for server inputs +import java.io.*; +import client.*; +import common.*; + +public class ServerConsole implements ChatIF{ + + //Class variables ************************************************* + + /** + * The default port to connect on. + */ + final public static int DEFAULT_PORT = 5555; + + //Instance variables ********************************************** + + /** + * The instance of the client that created this ConsoleChat. + */ + EchoServer server; + + + //Constructors **************************************************** + + /** + * Constructs an instance of the ClientConsole UI. + * + * @param host The host to connect to. + * @param port The port to connect on. + */ + public ServerConsole(int port)throws IOException{ ///////// see pics + server = new EchoServer(port,this); + } + + + + //Instance methods ************************************************ + + /** + * 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 server has shutdown."); + } + + /** + * 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) { + connectionClosed(); + } + + /** + * 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(); + server.handleMessageFromServerUI(message); + } + } + catch (Exception ex) + { + System.out.println + ("Unexpected error while reading from console!"); + } + } + + /** + * This method overrides the method in the ChatIF interface. It + * displays a message onto the screen. + * + * @param message The string to be displayed. + */ + public void display(String message) + { + System.out.println("SERVER MSG> " + 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) throws IOException + { + int port = 0; //The port number + + try + { + port = Integer.parseInt(args[0]); + } + catch(Throwable t) + { + 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 ServerConsole class diff --git a/code/simplechat1/client/ChatClient.java b/code/simplechat1/client/ChatClient.java index fe1401e..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..."); + } + } } @@ -62,20 +80,100 @@ public void handleMessageFromServer(Object msg) /** * This method handles all data coming from the UI * - * @param message The message from the UI. + * @param message The message from the UI. */ - public void handleMessageFromClientUI(String message) - { - try - { - sendToServer(message); - } - catch(IOException e) - { - clientUI.display - ("Could not send message to server. Terminating client."); + public void handleMessageFromClientUI(String message){ + + if (message.equals("#quit")) { + clientUI.display("Quitting..."); quit(); } + + else if (message.equals("#logoff")) { + try { + clientUI.display("Logging off..."); + 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: " +getPort()); + } + 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(); + } + } } /** @@ -90,5 +188,67 @@ 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() { + clientUI.display("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) { + clientUI.display("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() { + clientUI.display("The connection to the server has been established."); + } + + } //End of ChatClient class + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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