Question

Project Description In this project, you will be developing a multithreaded Web server and a simple...

Project Description

In this project, you will be developing a multithreaded Web server and a simple web client. The Web server and Web client communicate using a text-based protocol called HTTP (Hypertext Transfer Protocol).

Requirements for the Web server

  • The server is able to handle multiple requests concurrently. This means the implementation is multithreaded. In the main thread, the server listens to a specified port, e.g., 8080. Upon receiving an HTTP request, the server sets up a TCP connection to the requesting client and serves the request in a separate thread. After sending the response back to the client, it closes the connection.
  • The server is assumed to work with HTTP GET messages. If the requested file exists, the server responds with “HTTP/1.1 200 OK” together with the requested page to the client, otherwise it sends a corresponding error message, e.g., “HTTP/1.1 404 Not Found” or “HTTP/1.1 400 Bad Request”.
  • If running the server program using command line, the syntax should be:

server_code_name [<port_number>]

where the optional <port_number> is the port on which the server is listening to connections from clients. If the port number is not entered, the default port 8080 is used.

  • You can test your Web server implementation on your local machine using a Web browser, e.g., Internet Explorer, Firefox, or Chrome. You need to specify the used port number within the URL, for example,

http://localhost:8080/index.htm

If omitting the port number portion, i.e., 8080, the browser will use the default port 80.

  • The server should response with a default page when users do not enter a specific page in the URL, for example,

http://localhost:8080/

It should also work when the request includes a path to the requested file, for example,

http://localhost:8080/path/to/file/example.htm

  • You should display/log the request and header lines of request messages on the server for the purpose of debugging.

Requirements for the simple Web client

  • The client is able to connect to the server via a socket and to request a page on the server.
  • Upon receipt of the response message from the server, the client extracts and displays/logs the message status, and then retrieves the page content from the message body.
  • If running the client program using command line, the syntax should be:

client_code_name <server_IPaddress/name> [<port_number>] [<requested_file_name>]

where the <server_IPaddress/name> is the IP address or name of the Web server, e.g., 127.0.0.1 or localhost for the server running on the local machine. The optional <port_number> is the port on which the server is listening to connections from clients. If the port number is not entered, the default port 8080 is used. The optional <requested_file_name> is the name of the requested file, which may include the path to the file. If the file name is not entered, the default file “index.htm” is used.


I Just need help with the simple web client

Use Java

I used the eclipse IDE to develop the web server.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
mport java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;


public class Server_X_Client {
public static void main(String args[]){


    Socket s=null;
    ServerSocket ss2=null;
    System.out.println("Server Listening......");
    try{
        ss2 = new ServerSocket(4445); // can also use static final PORT_NUM , when defined

    }
    catch(IOException e){
    e.printStackTrace();
    System.out.println("Server error");

    }

    while(true){
        try{
            s= ss2.accept();
            System.out.println("connection Established");
            ServerThread st=new ServerThread(s);
            st.start();

        }

    catch(Exception e){
        e.printStackTrace();
        System.out.println("Connection Error");

    }
    }

}

}

class ServerThread extends Thread{  

    String line=null;
    BufferedReader  is = null;
    PrintWriter os=null;
    Socket s=null;

    public ServerThread(Socket s){
        this.s=s;
    }

    public void run() {
    try{
        is= new BufferedReader(new InputStreamReader(s.getInputStream()));
        os=new PrintWriter(s.getOutputStream());

    }catch(IOException e){
        System.out.println("IO error in server thread");
    }

    try {
        line=is.readLine();
        while(line.compareTo("QUIT")!=0){

            os.println(line);
            os.flush();
            System.out.println("Response to Client  :  "+line);
            line=is.readLine();
        }   
    } catch (IOException e) {

        line=this.getName(); //reused String line for getting thread name
        System.out.println("IO Error/ Client "+line+" terminated abruptly");
    }
    catch(NullPointerException e){
        line=this.getName(); //reused String line for getting thread name
        System.out.println("Client "+line+" Closed");
    }

    finally{    
    try{
        System.out.println("Connection Closing..");
        if (is!=null){
            is.close(); 
            System.out.println(" Socket Input Stream Closed");
        }

        if(os!=null){
            os.close();
            System.out.println("Socket Out Closed");
        }
        if (s!=null){
        s.close();
        System.out.println("Socket Closed");
        }

        }
    catch(IOException ie){
        System.out.println("Socket Close Error");
    }
    }//end finally
    }
// Client

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.Socket;

public class NetworkClient {

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


    InetAddress address=InetAddress.getLocalHost();
    Socket s1=null;
    String line=null;
    BufferedReader br=null;
    BufferedReader is=null;
    PrintWriter os=null;

    try {
        s1=new Socket(address, 4445); // You can use static final constant PORT_NUM
        br= new BufferedReader(new InputStreamReader(System.in));
        is=new BufferedReader(new InputStreamReader(s1.getInputStream()));
        os= new PrintWriter(s1.getOutputStream());
    }
    catch (IOException e){
        e.printStackTrace();
        System.err.print("IO Exception");
    }

    System.out.println("Client Address : "+address);
    System.out.println("Enter Data to echo Server ( Enter QUIT to end):");

    String response=null;
    try{
        line=br.readLine(); 
        while(line.compareTo("QUIT")!=0){
                os.println(line);
                os.flush();
                response=is.readLine();
                System.out.println("Server Response : "+response);
                line=br.readLine();

            }



    }
    catch(IOException e){
        e.printStackTrace();
    System.out.println("Socket read Error");
    }
    finally{

        is.close();os.close();br.close();s1.close();
                System.out.println("Connection Closed");

    }

}
}
Add a comment
Know the answer?
Add Answer to:
Project Description In this project, you will be developing a multithreaded Web server and a simple...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Part - Web Server Setup and Demonstration (AJ Objective The objective of this assignment is to...

    Part - Web Server Setup and Demonstration (AJ Objective The objective of this assignment is to some HTTP as application layer protocol and TCP as reliable transport layer protocol HTTP is carried by TCP. Also, in the assignment you will investigate the working of client-server mechanism from both application and networking perspective There are several different ways to setup an HTTP server, including through Apache Tomcat, Apache Glassfish that integrales in an IDE such as Eclipse/NetBeans or even a browser...

  • Objective: Create a proxy server that can be connected by a single client and would only...

    Objective: Create a proxy server that can be connected by a single client and would only allow http requests. Requirements: 1. Create a C based client-server architecture using sockets 2. The server should be able to accept and service single client’s http requests 3. The server should be run on cse01.cse.unt.edu machine and the client should be run on cse02.cse.unt.edu machine Procedure: 1. Create a C-based server that can accept single client’s request using sockets 2. The created server should...

  • Description: In this assignment, you will be launching a denial of service attack on a web...

    Description: In this assignment, you will be launching a denial of service attack on a web server. We will be using hping3, a command-line oriented network security tool inside Kali Linux (an advanced penetration testing Linux distribution). Setting up the victim machine Download the Windows XP virtual machine with WebGoat server installed, using the following link. We will use this machine as the victim machine and launch a DoS attack on the WebGoat server.https://drive.google.com/open?id=0BwCbaZv8DevUejBPWlNHREFVc2s Open the victim machine and launch...

  • Part I – Build a simple Servlet called MyServlet using NetBeans. Add this Servlet to you...

    Part I – Build a simple Servlet called MyServlet using NetBeans. Add this Servlet to you “ChattBank” Project. This MyServlet will display a message like “Go Braves” in a simple <h1> tag. Run this servlet from a Browser window by typing in the servlet name in the URL line. (ie. http://localhost:8080/ChattBank/MyServlet). Make sure that your Server is up and running before you test this Servlet. The best way to do this is just Run your “ChattBank” Project once before you...

  • Suppose within your web browser you click on a link to obtain a web page. The...

    Suppose within your web browser you click on a link to obtain a web page. The IP address for the associated URL is not cached in your local host, so a DNS look up is necessary to obtain the given IP address. Further suppose that 3 DNS servers are visited before your host receives the IP address form DNS. The round trip time between the client and the ithDNS server is Ti(1≤i≤3), and that between the jthDNS server and the...

  • Problem # 1 (30 points): Suppose within your Web browser you click on a link to...

    Problem # 1 (30 points): Suppose within your Web browser you click on a link to obtain a web page Suppose that the IP address for the associated URL is not cached in your local host, so that a DNS look- up is necessary to obtain the IP address. Suppose that two (2) DNS servers are visited before your host receives the IP address from DNS; the successive visits incur an RTT of RTT1 and RTT2. Further suppose that the...

  • 5.27 In this exercise we show the definition of a web server log and examine code...

    5.27 In this exercise we show the definition of a web server log and examine code optimizations to improve log processing speed. The data structure for the log is defined as follows: struct entry { int srcIP; // remote IP address char URL[128]; // request URL (e.g., “GET index.html”) long long refTime; // reference time int status; // connection status char browser[64]; // client browser name } log [NUM_ENTRIES]; Assume the following processing function for the log: topK_sourceIP (int hour);...

  • Here is the description of the client and server programs that you need to develop in C using TCP: Suppose we have a simple student query system, where the server keeps student's info in an array...

    Here is the description of the client and server programs that you need to develop in C using TCP: Suppose we have a simple student query system, where the server keeps student's info in an array of struct student_info ( char abc123171 char name [101 double GPA; To simplify the tasks, the server should create a static array of 10 students with random abc123, name, and GPA in the server program. Then the server waits for clients. When a client...

  • You can refer chapter 2 and chapter 3 of Computer Networking: A Top-Down approach by Kurose...

    You can refer chapter 2 and chapter 3 of Computer Networking: A Top-Down approach by Kurose and Ross for the following labs. Please read the instructions below for submissions. Upload the shared pcap file (Homework5.pacp) into wireshark. HTTP In this lab, we’ll explore several aspects of the HTTP protocol. Capture packets and filter for http protocol and answer the following questions. (Hint: Apply http filer) What version of HTTP version(1.0 or 1.1) is client running and what is the version...

  • You shall write a very basic web server in Javascript that will run via nodejs. Your...

    You shall write a very basic web server in Javascript that will run via nodejs. Your project shall include the following line: var paul   = require('/homes/paul/HTML/CS316/p3_req.js'); Your project will accept HTTP requests via URLs in the following format:       /[a-zA-Z0-9_]*.cgi Here are the steps you must perform for .cgi URLs: 1) call http .createserver(myprocess) my process() is a function you will write to process requests from the user via their browser 2) create a mylisten() function that takes the following parameters:...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT