February 25, 2002

 

 

CDA 4932 Distributed Systems and Applications Assignment 2

 

 

Please note that to successfully complete this assignment, you should have a Chat example working (see assignment 1 and assignment 1 follow-up).

 

In this assignment, you will implement a sorting server that will sort a supplied list of numbers (of fixed length) and return the result to the user.

Diagrammatically, it is shown below:

 

Server:

 

-Receive number string

-Parse number string for numbers

-Sort numbers

-Return sorted number string

 

Client:

 

-Send number string

-Receive sorted number string

-Display sorted number string

 

Both Server and Client are HLA Federates.

 

The following will have to be downloaded, installed and verified:

 

ü      Java Development Kit 1.3.x. To check if it is installed, open command prompt and type:

 

javac

 

If you get a “bad command or filename” error, you don’t have JDK installed. JDK is required if you want to compile a Java source file.

Java source files have extension .java and compiled Java files carry extension .class and are in the form of byte codes. You will have to

compile your Java files to see if they work.

 

JDK for Windows can be downloaded by clicking here. Follow the installation instructions at  http://java.sun.com/j2se/1.3/install-windows.html

General Java SDK documentation is available at http://java.sun.com/j2se/1.3/docs/index.html and has a few samples and all class definitions.

 

Make sure you set the CLASSPATH and PATH variables as described in the installation guide! Then, issue javac command at command

Prompt again. If you see javac <options>, you have installed JDK and set the PATH properly. However, this doesn’t guarantee that you’ve

set your CLASSPATH variable as required. When you first compile your Java source file and get an error “class not found”, you haven’t set

the CLASSPATH. The proper CLASSPATH should include <JDK Installation Folder>\lib\tools.jar

 

ü      Read the specifications carefully and fill out the pieces of code that were left out. Refer to http://java.sun.com/docs/books/tutorial/ for examples

on Java constructs and class libraries. The following should be downloaded into the same directory where you have Chat.class pRTI example:

 

Client.java – contains source code of a client with some parts omitted (see file). You will have to generate 10 random numbers, ranging from 0

to 100 and form a string of these numbers, separated by spaces. Then, you will print out unsorted string, preceded by “Unsorted List: ” Existing

code will send the string to the sorting server, which then returns a string of sorted numbers. You will have to print the received string, preceded

by the “Sorted List: ”. Then the client exits. Note: try to run two or more clients at the same time; observe the output.

 

Server.java – some parts of code have been omitted. Server receives a string of numbers from a client and prints it, preceded by the “Client

Request: ” string. You will have to parse the string and store the numbers in the array. Then, a sorting algorithm (of your choice, ascending order)

will sort an array of numbers. Finally, a string is formed from all the numbers in the array (separated by spaces). You will have to display the sorted

string, preceded by “Sorted List: ” The rest of the code for server is already in place – the string is sent to client(s). Server runs until interrupted by

the user by pressing Ctrl-C in Server window.

 

You will have to add code between the dashed lines in the source files. For instance,

 

// Add a code to display a sorted list here --------------------

 

      // -------------------------------------------------------------

 

Both Server and Client(s) run in separate command windows.

 

Hint: To parse a string into numbers, use StringTokenizer class, described at http://java.sun.com/j2se/1.4/docs/api/java/util/StringTokenizer.html

 

ü      Compile your Java source files by issuing the following command at command prompt:

 

javacclasspath prti.jar;jgl3.1.0.jar;"%CLASSPATH%" *.java

 

Make sure that prti.jar and jgl3.1.0.jar are in the same directory as your Java source files, or are included in CLASSPATH. If you get an error

you don’t understand, see Oleg during office hours, or e-mail him. If everything is compiled, you will get Server.class and Client.class files in the

same folder.

 

ü      Run the system: First, start pRTI, as described in Assignment 1. Then, start Server as follows:

 

java –classpath prti.jar;jgl3.1.0.jar;”%CLASSPATH%” Server

 

            You should see the Server in the list of active federates in the pRTI window. Now, start the Client as follows:

 

            java –classpath prti.jar;jgl3.1.0.jar;”%CLASSPATH%” Client

 

            The proper output should be displayed in the command window. For instance:

 

            Client Request: 2 51 48 75 6 54 23 3 14 7

     Sorted List: 2 3 6 7 14 23 48 51 54 75

     Client Request: 9 8 7 6 5 4 3 2 1 0

     Sorted List: 0 1 2 3 4 5 6 7 8 9

     Etc…  

 

ü      Submission: Write a report describing all your code, as well as any problems you have had. Submit the report and your Java source files

(Server.java and Client.java) on a floppy attached to the report. Your name has to be included in both source files as a comment on top.

 

 

 

 

Home