Lab iv | Computer Science homework help

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: http://google-styleguide.googlecode.com/svn/trunk/javaguide.
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: /127.0.0.1
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: /127.0.0.1
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 java.io.*;
import java.net.*;
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(System.in));
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 java.io.*;
import java.net.*;
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(System.in));
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

Calculate your paper price
Pages (550 words)
Approximate price: -

Why Choose Us

Quality Papers

We value our clients. For this reason, we ensure that each paper is written carefully as per the instructions provided by the client. Our editing team also checks all the papers to ensure that they have been completed as per the expectations.

Professional Academic Writers

Over the years, our Acme Homework has managed to secure the most qualified, reliable and experienced team of writers. The company has also ensured continued training and development of the team members to ensure that it keep up with the rising Academic Trends.

Affordable Prices

Our prices are fairly priced in such a way that ensures affordability. Additionally, you can get a free price quotation by clicking on the "Place Order" button.

On-Time delivery

We pay strict attention on deadlines. For this reason, we ensure that all papers are submitted earlier, even before the deadline indicated by the customer. For this reason, the client can go through the work and review everything.

100% Originality

At Essay USA, all papers are plagiarism-free as they are written from scratch. We have taken strict measures to ensure that there is no similarity on all papers and that citations are included as per the standards set.

Customer Support 24/7

Our support team is readily available to provide any guidance/help on our platform at any time of the day/night. Feel free to contact us via the Chat window or support email: support@acmehomework.com.

Try it now!

Calculate the price of your order

We'll send you the first draft for approval by at
Total price:
$0.00

How it works?

Follow these simple steps to get your paper done

Place your order

Fill in the order form and provide all details of your assignment.

Proceed with the payment

Choose the payment system that suits you most.

Receive the final file

Once your paper is ready, we will email it to you.

Our Services

Essay USA has stood as the world’s leading custom essay writing services providers. Once you enter all the details in the order form under the place order button, the rest is up to us.

Essays

Essay Writing Services

At Essay USA, we prioritize on all aspects that bring about a good grade such as impeccable grammar, proper structure, zero-plagiarism and conformance to guidelines. Our experienced team of writers will help you completed your essays and other assignments.

Admissions

Admission and Business Papers

Be assured that you’ll definitely get accepted to the Master’s level program at any university once you enter all the details in the order form. We won’t leave you here; we will also help you secure a good position in your aspired workplace by creating an outstanding resume or portfolio once you place an order.

Editing

Editing and Proofreading

Our skilled editing and writing team will help you restructure you paper, paraphrase, correct grammar and replace plagiarized sections on your paper just on time. The service is geared toward eliminating any mistakes and rather enhancing better quality.

Coursework

Technical papers

We have writers in almost all fields including the most technical fields. You don’t have to worry about the complexity of your paper. Simply enter as much details as possible in the place order section.