Server programs are rarely implemented as non-threaded applications, even though that is how you implemented your previous server application. Servers would not be able to provide the necessary throughput unless they used threading to allow for I/O to occur concurrently with servicing client requests. For this Assignment, you will modify your finger server program from Week 6 to use threads.
Modify your finger server program to use threads. The server should activate a new thread to process each incoming client request, thus allowing client requests to be processed concurrently.
FingerServer.java:
import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
public class FingerServer {
public static void main(String[] args) throws IOException {
ServerSocket serverSocket = new ServerSocket(79);
System.out.println(“The Finger Server is now ready!”);
while (true) { Socket socket = serverSocket.accept();
System.out.println(“Accepted an echo 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(“Client said: ” + line);
output.write(“Message from server: ” + line);
output.flush(); }
socket.close();
}
}
}
FingerClient.java:
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
public class FingerClient {
public static void main(String[] args) throws IOException {
int b;
if(args.length < 2) {
System.out.println(“Provide ip address and message through command line”);
return;
} Socket socket = new Socket(args[0], 79);
InputStream input = socket.getInputStream();
OutputStream output = socket.getOutputStream();
System.out.println(“The socket is connected the server.”);
System.out.println(“… local socket address is ” + socket.getLocalSocketAddress());
System.out.println(“… remote socket address is ” + socket.getRemoteSocketAddress());
output.write(args[1].getBytes());
socket.shutdownOutput();
while (true) { b = input.read();
if (b == -1) { break; } System.out.print((char) b);
}
System.out.println();
socket.close();
}
}
Delivering a high-quality product at a reasonable price is not enough anymore.
That’s why we have developed 5 beneficial guarantees that will make your experience with our service enjoyable, easy, and safe.
You have to be 100% sure of the quality of your product to give a money-back guarantee. This describes us perfectly. Make sure that this guarantee is totally transparent.
Read moreEach paper is composed from scratch, according to your instructions. It is then checked by our plagiarism-detection software. There is no gap where plagiarism could squeeze in.
Read moreThanks to our free revisions, there is no way for you to be unsatisfied. We will work on your paper until you are completely happy with the result.
Read moreYour email is safe, as we store it according to international data protection rules. Your bank details are secure, as we use only reliable payment systems.
Read moreBy sending us your money, you buy the service we provide. Check out our terms and conditions if you prefer business talks to be laid out in official language.
Read more