CONTENTS 1 Overview of Http Protocol 2 HTTP Package 2 (WWW) World Wide Web 3 Designing Http client

Authors Avatar

Question 1 - JAVA HTTP Client

Due to group deficit and misunderstandings I choose to work by my self as I hope this doesn’t have an effect on my behalf and also the teachers.

CONTENTS

  1. Overview of Http Protocol

  1. HTTP Package

      2    (WWW) World Wide Web 

3        Designing Http client

Also known as the ‘Hyper Text Transfer Protocol’, HTTP is responsible for the transferring of many different types of documents through the World Wide Web. HTTP version 1.1 is documented in RFC 2068; version 1.0 (deprecated) is documented in RFC 1945. This is basically a system that is used by a vast majority of users around the world to gain access to the web via their browsers

Http operates over TCP connections, usually to port 80, though this can be overridden and another port used. After a connection has been made, the client transmits a request message to the server, which sends a reply message back. HTTP messages are human readable.

The simplest HTTP message is "GET url", to which the server replies by sending the named document. If the document doesn't exist, the server will probably send an HTML-encoded message stating this. I say probably, because this simple method offers poor error handling and has been deprecated in favour of the more elaborate scheme outlined below

In HTTP 1.0 message begins like this “get url HTTP/1.0. The third field indicates that a full header is being used. The client then sends additional header fields, one per line that terminates the message with blank links. The server then replies in a similar way, by first a series of header lines, a blank line then the real document...

  • Below I have inserted an example of the HTTP 1.0 exchange and findings:-

GET / HTTP/1.0   >

                 >

                    < HTTP/1.0 200 OK

                    < Date: MON, 19 APR 2004 20:18:59 GMT

                    < Server: Apache/1.0.0

                    < Content-type: text/html

                    < Content-length: 1579

                    < Last-modified: Mon, 22 MAR 2004 22:23:34 GMT

                    <

                    < HTML document

In addition to the GET requests, clients can also send HEAD and POST requests, of which Posts are the most important. Posts are used for HTML forms and other operations that require the client to transmit a block of data to the server. After sending the header and the blank line, the client transmits the data.

The header must have included a Content-Length: field, which permits the server to determine when all the data has been received.

HTTP Package

Above is the package of the HTTP, Step to the each of the process.

(WWW) World Wide Web

There is always a gateway server active between the user agent and the content server. The content server is essentially the same as in the Web model above, but this time it hosts WML files alongside its HTML files. The primary job of the gateway server is twofold. First it must translate WAP protocols sent by the user agent into HTTP for communication with the content server. Secondly it must receive the requested content from the content server, encode the response into the appropriate WAP protocol and send it to the user agent. So, the communication between the user agent and the WAP gateway server is done with WAP protocols.

All messages use standard ASCII Code. Messages are set in pairs. The header field provides extra information. It also supports raw binary data.

Designing Http client

Diagram show: Request and respond between the http client and server

                                      

Http begins it transaction with a request command from the client to the server and has to get a respond command from the server to the client.

The communication between the WAP gateway and the content server is done with HTTP. As an example of the WAP model will consider what happens when a user types in and sends a request for a WAP page, for example www.mdx.ac.uk hosted on the Tessella Web server, from their mobile phone. The phone generates a GET request (part of the HTTP protocol) and sends it out over the air waves, first converting the GET message into a compact binary format that is more suitable for wireless transmission than the ASCII text format of HTTP. When the WAP gateway server receives the message, it parses it, converts it to a text based HTTP GET and forwards it to www.mdx.ac.uk.

The Middlesex University server receives the request, parses it and sends its response back to the gateway. If the GET request is valid the body of the response sent to the 3.

Gateway will contain a WML document. The WAP gateway receives the response, compiles it into a compact binary format and sends it over the airwaves to the mobile phone. The WAP phone then receives the message, parses the message body and displays the content on its screen.

HTTP SERVER CODE

import java.net.*;

import java.io.*;

import java.util.*;

public class httpServer1

{

    public static void main(String[] args)

    {

        // read arguments

Join now!

        if (args.length!=2) {

            System.out.println("Usage: java httpServer <80> <www.mdx.ac.uk>");

            System.exit(-1);

        }

        int port = Integer.parseInt(args[0]);

        String wwwmdx = args[1];

        

        // open server socket

        ServerSocket socket = null;

        try {

            socket = new ServerSocket(port);

        } catch (IOException e) {

            System.err.println("Could not start server: " + e);

            System.exit(-1);

        }

        System.out.println("httpServer accepting connections on port " + port);

           

        // request handler loop

        while (true) {

            Socket connection = null;

            try {

                // wait for request

                connection = socket.accept();

                BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));

...

This is a preview of the whole essay