0% found this document useful (0 votes)
45 views2 pages

DSPExercise02 1011

This document provides instructions for a classroom exercise on distributed systems programming. Students are asked to create a simple FTP client-server program using sockets and a message passing protocol. The program must allow the server to connect to a client, display the contents of a directory and text file to the client, and end the session. Students will initially test locally and then across multiple machines. The document also provides code snippets for reading files and listing directory contents to help with the exercise. Completing all exercises is worth 25% of the final assignment grade.

Uploaded by

krishansolanki
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views2 pages

DSPExercise02 1011

This document provides instructions for a classroom exercise on distributed systems programming. Students are asked to create a simple FTP client-server program using sockets and a message passing protocol. The program must allow the server to connect to a client, display the contents of a directory and text file to the client, and end the session. Students will initially test locally and then across multiple machines. The document also provides code snippets for reading files and listing directory contents to help with the exercise. Completing all exercises is worth 25% of the final assignment grade.

Uploaded by

krishansolanki
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Distributed Systems Programming

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.

Useful code snippets

//
// File reading code from
// Code from http://www.javapractices.com/topic/TopicAction.do?Id=42
//

/** Read the contents of the given file. */


String read(String fFileName) throws IOException {

StringBuffer text = new StringBuffer();


String NL = System.getProperty("line.separator");
Scanner scanner = new Scanner(new File(fFileName), fEncoding);
try {
while (scanner.hasNextLine()){
text.append(scanner.nextLine() + NL);
}
}
finally{
scanner.close();
}
return text;
}

Nigel Edwards DSP Ex1 2010/11


//
// Directory listing code from:
//http://www.java2s.com/Code/Java/File-Input-
Output/ListingtheDirectoryContents.htm
//
public class Dir {
static int indentLevel = -1;

static void listPath(File path) {


File files[];
indentLevel++;

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--;
}

public static void main(String args[]) {


listPath(new File("c:\\"));
}
}

2. Compare the use of TCP and UDP protocols java program, giving simple
code examples where appropriate.

Nigel Edwards DSP Ex1 2010/11

You might also like