Second Workshop Sheet: Clients and Server

 

 

Task 1:

Open two separate windows (MSDOS or whatever you use for compiling and running Java programs).  In one of them compile the TimeServer.java file and then run the resulting TimeServer.class file. In the other compile the TimeClent.java and run TimeClient.class. And then run TimreClient.class again.  Then open the ,java files in a window or print them., Study the files to try to understand how they work.

 

The files are located at

http://www.mcs.gold.ac.uk/~mas01rmz/CIS332/java/ClientServers/time/TimeClient.java

http://www.mcs.gold.ac.uk/~mas01rmz/CIS332/java/ClientServers/timeServer.java

Task 2:: (Ince:, Exercise 2.1)

The exercise consists of modifying the following Java Class

AddressFrame

You should develop a program that takes an IP address written in dotted quad notation and returns with the symbolic name of the computer that it identifies. You should modify the file by inserting code in the area indicates in the comment. The code should:

The processing above should be initiated by clicking the Go button in the frame. You will need to start up an Internet connection for this exercise to work if you are not going to use the loopback address for this. You will also need the dotted quad address of a computer to make this work; I suggest that you try 195.153.46.128 which is the address of the Guardian newspaper site

Most of the code provided is irrelevant to the exercise and you will not learn anything from looking at it, just concentrate on the parts indicated. You will need to write no more than 3 lines of Java code for this, two of which will access the visual objects.

---------------.

Task 3:(Ince:, Exercise 2.2)

This exercise consists of modifying the following file

EchoFrame

.This class represents a frame with three text fields: compField which contains the symbolic address of a computer (for example www.open.ac.uk), messageField which will contain a message which is to be sent to the echo port of the computer identified by compField and replyField which will contain the reply sent from the echo port.

You will need to fill in the code which does the sending and receiving of the messages. The code should be no more than six lines long. An important point to make about this exercise is that many computers disallow access to port 7 (the echo port) and an error message will appear on the MSDOS window or whatever UNIX window you are using; you will need to ask a friendly system administrator to allow you access. Often they will refuse access so the most you might get from this exercise is looking at the solution. This is one of the few exercises for which this is true.

The place at which you should insert code is indicated by comments, the area of the code that you should ignore is also commented. This is a general convention adopted in the remainder of the exercises.

The steps that we wish you to carry out are:

* Insert the code that is required for the exercise into EchoFrame.
* Execute the code in EchoFrame.
* You will see a frame displayed. Type in the name of the computer that you want to communicate with and the message that is to be sent.
* Check that the message has been sent back
* Quit the client by clicking on the top right hand x of the frame.

------------------

Task 4:(Ince:, Exercise 2.3

This exercise involves both a client and a server:   You will miodify the Client.  Find the two filews at:


           NameServer


            NameClient


In this exercise I want you to develop a small part of a client which accesses a server known as a name server. As you read the book you will realise that a name server is an important component of a distributed system. It stores data on the resources in a system and associates them with a symbolic name. I have provided you with the full code of a very simple name server, you do not need to modify this. What it does is to set up a very simple name database which associates the address of a computer (using the dotted notation) with some symbolic name. This is done in a very simple minded way: by using a Hashtable object and populating that object with name/address pairs. The server loops continually waiting for a client to send it the symbolic name of a computer; when it receives a name it looks it up in its database and sends back the address corresponding to the name; if it does not recognise the name then an error message is sent back.

What I want you to do is to fill in the code required for the client to communicate with the server. The client is based on a Frame object which has two text fields: one to hold the name typed in by the user (nameField) and another to receive the address sent back by the name server (addressField) . I have marked the insertion point for the code and also marked code that you should ignore.

The testing of the client and server will be carried out on the same computer running each as a separate program.

The steps that are required are:

* Read the code for the server and make sure that you understand it.
* Execute the server in an MSDOS window. You should see a number of messages being displayed by the server which should then wait for a client to access it.
* Code the Java required within NameClient 
* Execute the client solution in a second MSDOS window. You should see a frame displayed which asks you for the name of a computer. Type in one of the names in the first text field. The full set of names can be found in the code for the server.
* If the client is working correctly then you will see the name of the computer displayed on the second text field.
* Quit the client program by clicking the x in the top right hand corner of the executing frame.
and test it.
* To quit the client click the x in the top right hand of the executing frame.