Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need help understanding the threaded portion of this piece of Java code. Need to understand how to document the changes made and analyze the impact

Need help understanding the threaded portion of this piece of Java code. Need to understand how to document the changes made and analyze the impact the changes will have on the overall throughput and latency of the server.

Also need help with responses to these questions:

  • What other solutions might you consider in order to increase throughput and reduce latency?
  • Which solution do you consider to have the better trade-off between performance and complexity?
  • Which solution do you consider to have the better application of modularity, abstraction, hierarchy, and layering?

import java.io.*; import java.net.ServerSocket; import java.net.Socket;

class ServerThread extends Thread {

private BufferedReader input; private PrintWriter output; private Socket socket;

public ServerThread(BufferedReader input, PrintWriter output, Socket socket) { this.input = input; this.output = output; this.socket = socket; }

@Override public void run() { String line; try { while (true) { line = input.readLine(); if (line == null) break; System.out.println("Client said: " + line); output.write("Message from server: " + line); output.flush(); } socket.close(); } catch (IOException e) { e.printStackTrace(); } } }

public class FingerServer {

public static void main(String[] args) throws IOException {

ServerSocket serverSocket = new ServerSocket(79);

System.out.println("The ITEC 6120/8120 Finger Server is now ready!");

while (true) { Socket socket = serverSocket.accept(); System.out.println("Accepted a finger request"); System.out.println("... local socket address " + socket.getLocalSocketAddress()); System.out.println("... remote socket address " + socket.getRemoteSocketAddress()); BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream())); PrintWriter output = new PrintWriter(socket.getOutputStream()); String line; while (true) { line = input.readLine(); if (line == null) break; System.out.println("FingerClient: " + line); output.write("FingerServer: " + line); output.flush(); }

socket.close(); }

} }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Practical Issues In Database Management A Refernce For The Thinking Practitioner

Authors: Fabian Pascal

1st Edition

0201485559, 978-0201485554

More Books

Students also viewed these Databases questions