Details of this Paper

lab iv




CISC 3120:Design and Implementation of Software Applications I -;Zimi Li - Lab IV.2;instructions;This is the second lab for unit IV.;The lab will be distributed and worked on in class on Apr 3.;This lab is due at 11:59pm, Apr 9 and must be submitted through blackboard system.;Grading policy;20 points - Compilation: Each le must compile without error or warning into a class le.;20 points - Execution: Each executable must run without error or warning on valid input using the;command line parameters described above.;30 points - Correctness: Is/Are the algorithm(s) implemented correctly? Have an appropriate number;of word/document representations been used and used correctly?;10 points - Style: Is the structure of your program clear and coherent? Are functions and variables given;self-explanatory names? Are functions used to aid intelligibility of the code? Are functions used to reduce;repeated blocks of code? Is indentation, spacing, use of parentheses, use of braces consistent, and sensible?;For example, if you use brackets on the same line at the start of a block, always do so. If you place a;brace on the line following the start of the brace, always do so. If you put a space between variables and;operators, e.g. if (i == j), always do so. So, if (i == j) i = j+k, is bad. It should be if (i == j) i = j + k;or if you prefer if (i==j) i=j+k,. You will be graded on consistency in these decisions, not on any particular;style.;10 points - Comment: Every function should include a comment minimally describing;1. what it does;2. what its inputs are;3. what its output is;4. who the author is;You may use a javadocs. Are there eective other comments throughout the code? For a good read check;out the google style guides:;html;10 points - Instructor's Discretion Has this assignment gone beyond the minimal requirements in;a substantive way? Is it especially clear? Is the code especially well written? Is the response particularly;thoughtful or insightful? Have non-trivial representations been examined?;1;1 Chatter;Chatter is a trivial client/server application that provides a very basic introduction to socket-level programming.;The application consists of two parts{ the server and the client.;1.1 The Chatter Protocol;Once a connection is established, the server talks rst (we simply have it ask the client what it wants). The client;then responds and the two sides continue to alternate{ thus neither side can send two consecutive messages{ the;other side must rst respond.;1.2 Chatter Server;The server creates a ServerSocket on the well-known port 3333 (well, the port number is at least well known for;anyone who wants to become a client of the Chatter server), and uses the accept method to wait for a request.;Once the request arrives (in the form of a client socket being returned from the accept method), the server prints;out identifying information about the client{ this information is available from the client socket.The server then;obtains the input and output streams associated with the client socket.;Communication now proceeds according to the above protocol;The server sends the initial 'welcoming' message (on the client socket's output stream);It then (waits and) reads the response (from the client socket's input stream);This repeats until someone terminates the connection (in our case by stopping the program);1.3 Chatter Client;The client accepts a command line argument corresponding to a the machine the user wishes to chat with. It;creates a (client) Socket using the machine name and the well-known port 3333 (note how the client must know;the value of the server's well-known port). The client then obtains the input and output streams associated with;the socket;Communication now proceeds according to the above protocol;The client waits for the server's 'welcoming' message (on the socket's input stream);It then sends its own response to the server (on socket's output stream);This repeats until someone terminates the connection (in our case by stopping the program);Note how the client's output stream corresponds to the server's input stream and vice versa.;1.4 Deploying;The application may be run by invoking the server class in one Command Prompt window;java ChatterServer;and the client in a second Command Prompt window;java ChatterClient localhost;1.5 Things To Do;Download the application (both ChatterServer and ChatterClient) to your machine, make sure you can run;it using localhost (i.e., talking to yourself).;Try talking to someone else using remote server.;Once you've gotten familiar with this, you can start the real assignment;2;Modify the Chatter protocol so that whenever one side talks, they continue talking as long as the line they;send contains a "...". Thus if it's the server's turn, and the server writes;I went to class today...;the server continues to be the one to send data. If the server then writes;but the room was locked;it now becomes the client's turn.;If the client closed the connection, the server must keep running.;Save the log to le ChatterLog.log. Remember to;ush the stream.;1.6 How To Submit;Deploy the server part at your homework server as background application (using &). I will post the port;that everyone should use.;Whatever the client talks, you must reply;Your Name...;The port number you are using;Save all the server log to the le ChatterLog.log.;1.7 Example;Server;Waiting for a client;Connection requested from: /;Hi;Your turn> Zimi Li...;Your turn> 10050;Client;Whatcha want?;Your turn> Hi;Zimi Li;10050;Your turn> (waiting for input);Log;Waiting for a client;Connection requested from: /;Client> Hi;Server> Zimi Li;Server> 10050;2 Debrief;Attach a text le answering these questions;Did you work alone, or did you discuss with other students? List their names.;How many hours did you spend on this assignment?;Would you rate it as easy, moderate, or dicult?;3;Are the lectures too fast, too slow, or just in the right pace?;Any other comments?;3 Additional Information;3.1 ChatterServer;import*;import*;public class ChatterServer;public static void main(String [] args) throws Exception;ServerSocket serverSocket = new ServerSocket(SERVER_PORT);System.err.println("Waiting for a client");Socket clientSocket = serverSocket.accept();System.out.println("Connection requested from: " + clientSocket.getLocalAddress());PrintWriter toClient = new PrintWriter(clientSocket.getOutputStream(), true);BufferedReader fromClient = new BufferedReader(new;InputStreamReader(clientSocket.getInputStream()));BufferedReader keyboard = new BufferedReader(new InputStreamReader(;toClient.println("Whatcha want?");String incoming = fromClient.readLine();while(incoming != null);System.out.println(incoming);System.out.print("Your turn> ");String myReply;myReply = keyboard.readLine();toClient.println(myReply);incoming = fromClient.readLine();final static int SERVER_PORT = 3333;4;3.2 ChatterClient;import*;import*;public class ChatterClient;public static void main(String [] args) throws Exception;Socket serverSocket = new Socket(args[0], SERVER_PORT);PrintWriter toServer = new PrintWriter(serverSocket.getOutputStream(), true);BufferedReader fromServer = new BufferedReader(new;InputStreamReader(serverSocket.getInputStream()));BufferedReader keyboard = new BufferedReader(new InputStreamReader(;String incoming = fromServer.readLine();while(incoming != null);System.out.println(incoming);System.out.print("Your turn> ");String myReply;myReply = keyboard.readLine();toServer.println(myReply);incoming = fromServer.readLine();final static int SERVER_PORT = 3333;5


Paper#68880 | Written in 18-Jul-2015

Price : $34