Distributed Systems (W4995-2) -- Fall 2012 |
This is a warm-up exercise before the actual yfs series labs, which requires basic UNIX network programming knowledge. Note that you need to use C/C++ and pure socket API to finish this lab - other languages and external libraries are not accepted. If you are not comfortable with this lab, you will probably reconsider taking this course.
You will need to implement a client-server application. The client connects to server using TCP and sends it the name of a file, and the server then looks up the file in the predefined directory. If the file exists, it returns the content of the file to the client side, and the client side saves it as a local file. Moreover, you will need to implement a cache. That is to say, if the file being requested by a client is previously requested, it will read the file directly from cache instead of reading it from disk. The cache can only use no more than 60 MB memory.
More specifically, the logic of the program looks like this:
You do NOT need to implement a multi-threaded server - a single thread version will be fine.
You are required to handle error gracefully. You will need to check the return value of each function, such as bind and receive. Should there be any error, you will print out the corresponding error message.
The server side takes 2 parameters - the port to listen on and the directory to find the file. It looks like this:
% tcp_server port_to_listen_on file_directory e.g. % ./tcp_server 9089 /home/dist/lab0The above argument will make the server listen on port 9089 and look up file in /home/dist/lab0.
The client side takes 4 parameters - the server name, server port, the file to request, and the local directory to save the file in. It looks like this:
% tcp_client server_host server_port file_name directory e.g. % ./tcp_client 59.78.58.28 9089 lab0.html .The above argument will make the client connect server 59.78.58.28:9089 and request file lab0.html and save it in the current directory.
A typical output on the server side looks like this:
% ./tcp_server 9089 /home/dist/lab0 Client 59.78.55.65 is requesting file lab0.html Cache miss. lab0.html sent to the client Client 59.78.55.66 is requesting file lab0.html Cache hit. lab0.html sent to the client Client 59.78.55.66 is requesting file lab1.html Cache miss. lab0.html sent to the client Client 59.78.55.65 is requesting file lab0.html Cache hit. lab0.html sent to the client
A typical output on the client side looks like this:
% /tcp_client 59.78.58.28 9089 lab0.html . lab0.html saved
In addition to the source code, you will also need to write a Readme file containing the following information:
We will test your code in CLIC boxes. Failure to compile in such environment will lead to a ZERO!
Your program will be graded on the basis of (1) how well you handle errors, how good your coding style is (see Policies), and how thorough your Readme file is. The test cases under which we will test your program will explicitly try to test for error conditions. Unless your program fails gracefully with meaningful error message under all test cases, we will deduct points off your grade for each assignment. Hence, you will want to test your system very thoroughly before submitting it, and document your test cases in the Readme. An incomplete Readme will result in minus points, so be as thorough as possible!
We will also severely deduct points if your code is messy. Please consider reading (parts of) a style guide, such as Google's style guide for C++.
Make sure you read the collaboration policies before you begin. You must write all of your code yourself! We will check portions of your code online automatically, so do not attempt to use online code for this assignment. A late assignment will get a ZERO, so please submit before the deadline!
We thoroughly believe that a good programmer writes every line of code as carefully as if it were the most critical line of code he's ever written! You need to learn (or rehearse) being a great programmer, and this assignment, however simple, is yet another opportunity to do so. You should use the grade and our comments as an opportunity for you to learn how to improve.