Java Assignment Sample

java homework solutionBelow you will find a sample of HTTP proxy server assignment completed by our experts in Java. Do you have a similar homework task? Hire our Java tutors and we will provide you with a custom solution right on time.

Assignment Details

In this assignment, you will implement a web proxy that passes requests and data between multiple web clients and web servers, concurrently. This will give you a chance to get to know one of the most popular application protocols on the Internet — the Hypertext Transfer Protocol (HTTP) – and give you an introduction to the sockets API. When you’re done with the assignment, you should be able to configure your web browser to use your personal proxy server as a web proxy.

Java Code

Server Version 1:
import java.io.*;
 import java.net.*;
 class TCPClient
 {
  public static void main(String argv[]) throws Exception
  {
   String sentence;
   String modifiedSentence;
   BufferedReader inFromUser = new BufferedReadernew InputStreamReader(System.in));
   Socket clientSocket = new Socket("localhost", 6789);
   DataOutputStream outToServer = new DataOutputStream(clientSocket.getOutputStream());
   BufferedReader inFromServer = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
   sentence = inFromUser.readLine();
   outToServer.writeBytes(sentence + '\n');
   modifiedSentence = inFromServer.readLine();
   System.out.println("FROM SERVER: " + modifiedSentence);
   clientSocket.close();
  }
 }
Server Version 2:
import java.io.*;
 import java.net.*;
 class TCPServerV2
 {
    public static void main(String argv[]) throws Exception
       {
          ServerSocket welcomeSocket = new ServerSocket(6789);
          while(true)
          {
             new TCPServerThread(welcomeSocket.accept()).start();         }
       }
 }
import java.io.*;
 import java.net.*;
 import java.util.*;
 class TCPServerThread extends Thread
 {
 private Socket connectionSocket = null;
 public TCPServerThread(Socket theSocket)
    {
         super(“TCPServerThread”);
         this.connectionSocket = theSocket;
      }
    public void run()
       {
          String clientSentence;
          String capitalizedSentence;
       try{
             BufferedReader inFromClient =
             new BufferedReader(new InputStreamReader(connectionSocket.getInputStream()));
          DataOutputStream outToClient = new DataOutputStream(connectionSocket.getOutputStream());
          clientSentence = inFromClient.readLine();
          System.out.println("Received: " + clientSentence);
          capitalizedSentence = clientSentence.toUpperCase() + '\n';
          outToClient.writeBytes(capitalizedSentence);
          connectionSocket.close();
}
      catch (Exception e){ }
     }
}

Get your own java homework solution from our writers!