You are on page 1of 3

16.583/16.

483 Network Design: Principles, protocols and Applications Spring 2010 LAB Assignment #2

Your solutions should include answers to the verbal questions, and the source code of your programs. Please describe the system you are using to conduct your experiments. The Simple File Transfer Protocol The objective of this assignment is to implement a simple client-server model based on the well-known ftp program. You are required to write programs for a client process and a server process with the following behavior: Client: takes the host machine of the server as an argument. It connect to the server at a pre-specified port. The client repeatedly prompts the user to input a command (see below), and sends it to the server. Server: repeatedly receives a command and processes it, and replies. Commands: list : send the list all files in the current directory at the server cd : change the current directory at the server get filename : a request for the server to send over a file filename. put filename : a request for the server to put a file filename. quit : the client shuts down.

The protocol. The client sends its requests on the main socket connection: these are the strings entered by the user, followed by a newline (use gets). The serverresponds to each message with either the string "huh?" indicating an error, or a string "OK port" (in the case of quit and cd, "OK" only). In case that the request is not erroneuos, port indicates a new socket the server has opened to deal with the data (called "data socket", whereas the main socket is the "control socket"). The client should connect to this port to receive the data (in case of get and list) or to send it (in case of put). In the data socket, information is passed as follows: the first bytes indicate the number of bytes in the data; then a " " byte (0x20: blank space); and finally the data. This protocol is followed whether the data is flowing from the server to the client (get and list) or from the client to the server (put).

Status DoOperation(Command *msg, Reply *reply, Socket s, SocketAddress serverSA);

Status GetRequest(Command *msg, Socket s, SocketAddress *clientSA); Status SendReply(Command *reply, Socket s, SocketAddress clientSA); DoOperation sends a command msg to address serverSA via a socket s; then it blocks until it gets a reply, which is returned using the pointer reply. GetRequest receives a command msg via a socket s. The address of the origin of the message is returned using the pointer clientSA. Note that the structure of

other server modules processing the request id left for you to design.
SendReply sends a message reply via a socket with descriptor s to the address clientSA.

The functions above will use the communication functions sendTCP and receiveTCP which you will write. The return values of DoOperation, GetRequest, and SendReply will reflect the return values of the communication values they use.
Status sendTCP(Socket s, char* buff, int len); Status receiveTCP(Socket s, char* buff, int* len); SendTCP sends len bytes starting at address buff through socket s to address destination. receiveTCP receives a message from the socket s, places it in buffer buff, and puts the address of the sending socket in origin. The len argument is a pointer to an integer which is used as a value-result parameter: initially, *len is the maximal capacity of the buffer; when the call returns, *len holds the number of bytes actually filled by receiveTCP. The communication functions are to be implemented using read and write. The Status values returned by the functions report the success or the failure of the function. E.g., if the write called by sendTCP returns a negative value, sendTCP can return a value SEND_FAILURE.

Cleanup. Don't forget to kill your processes when you're done! Otherwise, system tables are jammed quite quickly. See the man page for kill. Basic Requirements - The client and the server should work correctly when run on two separate machines. - The server should still work when there are two different clients . - Add a timeout in the client program: if there is no reply from the server after 3 seconds, the client re-sends its request up to three times. If there is no reply after three times, the client reports this fact. You can use the function AnythingThere provided in the appendix to implement the timeout . - The solutions should include a clear write-up as documentation.

Extra Credit - Implement the above without using the system call.

Add quantitative indications: what is the length of the file transferred, what is the transmission time, what is the transmission rate. Add compression to the file transfer. You might wish to change the basic protocol: that's OK, so long as you document these changes. Implement the SFTP server in Java . Sample code is given in Appendix B. Extra credit will be given for a multithreaded server implementation. Extend the basic protocol suite in any way you think is interesting from the communication viewpoint. Points allocated by the result.

Reference You may find it useful to read how the real FTP protocol works. It is described in RFC 959 (subject to RFC 1123). Appendix A: checking for input with timeout The function AnythingThere uses the select system call to test whether there is any outstanding input on a socket s in a time interval of length TIMEOUT_SECONDS. #include <sys/types.h> #include <sys/time.h> int AnythingThere(int s) { fd_set read_mask; struct timeval timeout; int ret; timeout.tv_sec = TIMEOUT_SECONDS; timeout.tv_usec = 0; FD_ZERO(&read_mask); FD_SET(s, &read_mask); if ((ret = select(32, &read_mask, 0, 0, &timeout)) < 0) report_error("select"); return( (ret == 0) ? NOTHING_THERE : SOMETHING_THERE ); }

You might also like