Académique Documents
Professionnel Documents
Culture Documents
Classroom Exercises 2 of 5
These exercises should be completed during supervised lab time and should be
handed in as an appendix to the major assignment at the end of week 12. The
combined total for all the exercises constitutes 25% of the multiphase
assignment mark.
1. Create a small console base java program which acts as a simple ftp
(type) server and client using sockets and a simple message passing
protocol.
a. You need to define a protocol that will instruct the server to:
i. Connect the client to the server.
ii. Display the contents of a directory to the client.
iii. Display the contents of a text file resident on the server to
the console of the client.
iv. End the session
b. Initially test your program on a single machine, once testing is
complete liaise with fellow students to test your machine across
multiple machines.
//
// File reading code from
// Code from http://www.javapractices.com/topic/TopicAction.do?Id=42
//
files = path.listFiles();
Arrays.sort(files);
for (int i = 0, n = files.length; i < n; i++) {
for (int indent = 0; indent < indentLevel; indent++) {
System.out.print(" ");
}
System.out.println(files[i].toString());
if (files[i].isDirectory()) {
listPath(files[i]);
}
}
indentLevel--;
}
2. Compare the use of TCP and UDP protocols java program, giving simple
code examples where appropriate.