ICT214 O/O Design and Programming

Assignment One
Semester 1, 2008

Introduction

This assignment is the first of two, which are linked: the first assignment will be extended and added to for the second one.

Client server applications form the basis for nearly all network applications. In this style of programming one part of the application runs as a server on one computer while the other part runs as a client on another computer. A common application is for file transfer, where a client is able to discover files on a server and copy them from the server to the client's computer. This assignment will do a simple form of a file transfer application.

Details

You will need to implement a console-based application that will read user instructions from the console and send commands to a server. It will read responses from the server and write them to the user. For this assignment just the client needs to be written. It can be tested against a server supplied by the lecturer. For the second assignment, you will write the server as well, and also improve the client with a graphical user interface (GUI).

The server will run on port 2008. A client will need to be supplied with the server's address (e.g. by a command line argument). The client will then connect to the server and start sending commands and reading responses.

The client will send commands as a single line of text. The server will reply with one or more lines of text or a stream of bytes. Each line from the client will be terminated with a CR-LF pair. All messages will be encoded using the ASCII character set. The commands sent by the client will be

Command Meaning
GETCWD Get current working directory
CHDIR <directory> Change current working directory
LIST List files in current directory
GET <file> Get a text file's contents
QUIT End this session

The responses sent by the server will be

Client Command Response
GETCWD One line of text containing the directory name
CHDIR <directory> SUCCESS or FAIL
LIST One line with a number saying how many files will be listed, followed by each filename, one per line
GET <file> One line with a number saying how many bytes are in the file and then a byte stream of that length. If there is an error in accessing the file, then there is only one line returned, containing "-1"
QUIT No response, the connection is closed
Any other requests will get a return of "ERROR". Each line of text will be terminated by a CR-LF pair. Each text message will be encoded in the ASCII character set.

For simplicity, only text files can be got using this server.

Deliverables

You should hand in the following

You will be asked to demonstrate your system. This will be in the tutorial of the week of submission.

Group size

This assignment (and the next one) must be done individually.

Due date

The assignment is due in the class of Week 7, Tuesday April 1.

Example server

An example server is in server.jar . Save it as server.jar and run this by


java -jar server.jar


Jan Newmarch (http://jan.newmarch.name)
jan@newmarch.name
Last modified: Mon Mar 3 19:47:29 EST 2008
Copyright ©Jan Newmarch