Home > Java > Simple Java Assignment

Simple Java Assignment

November 15th, 2009

Purpose:
The purpose of this project is to familiarize the student with the some of the concepts of peer-to-peer computing.
Description:
To do this we will create a servant program similar in function to (but simpler than) Gnutella. The program will consist of two main functions: an HTTP based client similar to a web browser but much simpler and a simple HTTP server. The server used for the HTTP homework assignment can be used and modified for the server portion of the servant. The client and server portions of the servant should run independently of one another (on seperate threads) and the server itself should be threaded so that it can serve multiple clients simultaneously. Inter-servant communications should be limited to standard GET and POST HTTP transactions. Intra-servant communications (between the client and server of the same servant) should be limited to only the minimum required for passing queries on to other servants.
For additional information refer to the class notes and the Gnutella web site.

Specifications:
Server Connection Port: 4911
Protocol: HTTP 1.0
Max Time to live: 3
Local Database: each servant needs to keep a local database that will keep track
of the following: IP address or host name of other on-line servants
Time to live for each connected servant
Files available from each on-line servant
Queries: each client should allow the user to request either a complete directory
list of its file store or a directory list for a specific file type (ex .doc, .jpg).
Queries should be automatically propigated to each community member (until the time to
live has expired; time to live is decremented by one as a query is propigated
to additional servants, when it reaches zero it isn’t propigated any farther).
To pass the TTL and the query from one servant to the next embed the TTL and
Query in the HTTP header as name/vale pairs as if they had been POSTed from
an HTML form.

File Formats:
Directory List File:
line 1 – IP Addr of original requestor n
line 2 – Original Query n
line 3 – filename.filetype n
.
.
.
line n – filename.filetype n

Request and Response Headers:
Request Header:

line 1 – POST / HTTP/1.0
line 2 – Connection: Keep-Alive
line 3 – User-Agent: CS328-Servant
line 4 – Accept-Language: en
line 5 – Content-type: application/x-www-form-urlencoded
line 6 – Content-length:
line 7 –
line 8 – QUERY=JPEG&TTL=3&ORIGIP=128.226.121.nnnn&SUBMIT=Submit

Response Header:
line 1 – “HTTP/1.0 200 OKn”
line 2 – “Allow: GETn”
line 3 – “MIME-Version: 1.0n”
line 4 – “Server: CS328 Basic HTTP Servern”
line 5 – “Content-Type: ” + contentType + “n”
line 6 – “Content-Length: ” + fileLength + “nn”;
Hints:
To make testing easier start out by writing your servant as two seperate programs, first using a regular web browser (Firefox or IE) make sure that your server will serve a directory list of its document store; next make sure that your client can connect to the server and that it can request and display the directory list from your server. Now put the client and server together into a single program and retest everything again.
To retrieve a file from one of the other servants you may either issue an HTTP Get for the specific file directly from the owning servant or retrieve it directly from the owning servant using the URL class in the java.net.* library.


Simple Java Assignment

Categories: Java Tags: , , , , , ,
Comments are closed.
Bear