Reference no: EM132387263
CNCO3002 Advanced Computer Communications
Discipline of Computing - Curtin University, Australia
Assignment - My Proxy Server
Objective - The objective of this network programming assignment is to develop three complementary programs: Client, Proxy Server and Server, which implement a simple application program, called My Proxy Server (MPS). Note that the idea behind MPS is the Web Proxy Server of HTTP/1.1. However, MPS does not follow the standard for Web Proxy Server of HTTP/1.1 as specified in RFC 2616.
Without a Proxy Server, when a Client C requests for a file X stored in a Server S, the request is sent directly from C to S. Server S then processes the request and sends the requested file X directly to Client C.
To improve performance, a Proxy Server P is inserted between Client C and Server S. As shown in Figure 1, MPS contains three main entities: one Proxy Server, a set of Servers, and a set of Clients; the figure shows only three of the Servers and one of the Clients. The Proxy Server serves requests from each Client on behalf of each actual Server. The Proxy contains disk storage to keep / cache the recently requested files by the Clients. Let the cached files be in directory my_cache of the Proxy Server. Initially, my_cache is empty.
Requirements -
1) Write a pre-threaded TCP concurrent Proxy Server program P that is waiting for some Client C at its port L. Use one of your assigned port numbers for L. You also need to write one program to implement Client C, and another program to implement Server S. Each concurrent Server S is waiting for clients at port K. Use one of your assigned port numbers for K. Any server design, e.g., pre-threaded, pre-forked, etc. for the Server is acceptable.
2) For each connection from Client C, Proxy P uses one available thread from its pool of threads, e.g., P-C, which will serve Client C. The client shows a prompt Client > when waiting for a valid command from its user, e.g., you or the grader.
3) Each Proxy P-C recognizes the following set of commands from Client C (not case sensitive).
a) LOOK cache
e.g., Client > LOOK cache
Given the user's command, Client C sends the command to P-C. Receiving the command, P-C sends the content of cache table to Client C. P-C then waits for the next request from Client C. Receiving the content of cache_table, Client C shows the content on its screen, and shows prompt Client > to wait for another user command. You can decide the format of the printed cache_table on the screen, e.g.,
File1
Location: 137.7.5.22, 51000
Cached time: Fri Jan 13 10:27:52 2017
Last requested time: Fri Jan 13 14:27:52 2017
Total requests: 5
File2
Location: 137.7.5.23, 50002
Cached time: Fri Jan 13 13:27:52 2017
Last requested time: Sat Jan 14 1:30:43 2017
Total requests: 2
File3
Location: 137.7.5.22, 51000
Cached time: Fri Jan 13 12:17:22 2017
Last requested time: Fri Jan 13 15:47:12 2017
Total requests: 1
File4
Location: 137.7.5.24, 50001
Cached time: Fri Jan 13 10:29:52 2017
Last requested time: Fri Jan 13 17:47:12 2017
Total requests: 1
b) GET Server Port File_name
e.g., Client > GET Server1 51000 File1
Client C wants to download File_name (e.g., File1) from Server (in dotted decimal notation) with port number Port. Client C sends the command to Proxy P-C. Receiving the request, Proxy P-C checks cache_table to see if there is a valid File_name in my_cache.
(i) If File_name in my_cache is valid, Proxy P-C sends File_name to Client C, updates the Last requested time with the current time, and increases Total request by one. Proxy P-C then waits for the next request from Client C.
(ii) If File_name has not been cached or it is not valid, Proxy P-C creates a TCP connection to Server S (e.g., Server1) that is listening at Port K to request for File_name. For K, use your assigned port number. Receiving the request, Server S sends File_name to Proxy P-C, closes the connection, and waits for another TCP connection. Receiving File_name, Proxy P-C sends it to Client C, stores / replaces File_name in my_cache, and adds information about File_name in cache_table, e.g., row 4 in the example cache_table for File4. Note that Proxy P- C replaces File_name in my_cache if there is an invalid copy of File_name in my_cache. Proxy P-C then waits for the next request from Client C.
Receiving File_name, Client C stores File_name in its directory download-file, prints a message to its screen (e.g., "File_name is downloaded"), and shows prompt Client > to wait for another user command.
c) DELETE Server Port File_name
e.g., Client > DELETE Server1 51000 File1
The user of Client C wants Server S to delete the File_name (e.g., Server1 listening at Port 51000 to delete File1). Client C sends the command to Proxy P-C.
Receiving the command, Proxy P-C creates a TCP connection to Server S (e.g., Server1) that is listening at Port K, and forwards the deletion message to Server S, and waits for a reply from Server S. Receiving the deletion message, Server S checks if File_name is in its my_file. If yes, Server S deletes File_name from my_file, and sends a success message (e.g., "OK; File1 has been deleted") to Proxy P-C and closes the connection with Proxy P-C. Otherwise, it sends a failure message (e.g., "File1 does not exist") and closes the connection with Proxy P-C. Receiving the message from Server S, Proxy P-C forwards the message to Client C. Proxy P-C also checks if there is an entry about File_name in its cache_table. If so, Proxy P-C deletes the entry, and removes File_name from my_cache. Then, Proxy P-C waits for the next request from Client C. Receiving the message from Proxy P-C, Client C prints the result of its DELETE command, e.g.,
Deleted File1
Location: 134.7.7.34, 51000
Then, Client C shows prompt Client > to wait for another user command.
d) EXIT
e.g., Client > exit
Client C wants to exit MPS. Receiving the request, Proxy P-C sends a "good bye message" to Client C, and terminates the connection. Receiving the message, Client C shows the message on its screen, and then terminates the connection, e.g.,
Good bye Client (IP address, Port number). Thank you for using MPS!
In the example, IP address and Port number are respectively the address and port number of Client C.
4) The Proxy Server, Server, and Client must check for some possible invalid commands and errors, e.g., attempt to download a non-existing file, etc., and address them properly.
5) Each Proxy Server P-C terminates connection with Client C if it does not receive any command within x seconds. Set the value of x when you run the Proxy Server program, i.e., as part of the command line argument.
6) Your program must address all necessary mutual exclusion.
7) How to test your programs? You first run your Proxy Server program. Then, you run one or more Servers. Note that you need to create five files in each Server. Finally you run one or more clients to connect to the Proxy Server, and test each command.
Your assignment report should include:
A signed statement that the assignment is your own work, which includes the words "Advanced Computer Communications Assignment", and your name in the form: family, other names. Your name should be as recorded in the student database.
Software solution of your assignment that includes (i) all source code for the programs with proper in-line and header documentation. Use proper indentation so that your code can be easily read. Make sure that you use meaningful variable names, and delete all unnecessary comments that you created while debugging your program; and (ii) readme file that, among others, explains how to compile your program and how to run the program.
Detailed discussion on how any mutual exclusion / synchronization is achieved and what threads access the shared resources.
Description of any cases for which your program is not working correctly or how you test your program that make you believe it works perfectly.
Sample input and output for the program.
Attachment:- Advanced Computer Communications Assignment File.rar