Network Programming: Project 2.

Introduction

In this project you need to create a small FTP server. Well, it won't be exactly FTP server because the protocol you need to implement is not the FTP, but the program you will create is expected to transfer files. Your project is to contain two programs the server and the client. Server programs starts, creates a TCP socket and waits on a specific port for connection from client programs. When a client program connects to the server via this TCP port (we'll call this connection the "control" connection) it can send commands to the server. Server should respond to these commands with either requested data or messages inform the client about the result of the command.

Commands

You need to make you server and client to understand and run the following commands:
  1. LIST [client -> server] - get the list of all files in the current server directory
  2. CD dirname [client -> server] - change the current server directory
  3. GET filename [client -> server] - download the file "filename" from the server
  4. CONTINUE filename offset [client -> server] - resume downloading the file "filename" from the server starting from the byte "offset"
  5. PORT portnumber [client -> server] - set a port number for the "data" connection
  6. WINDOW size [client -> server] - set the number of blocks the server can send without getting them ACKed
  7. BLOCK size [client -> server] - set size of the block. Meaning that the data sent over the data connection can not exceed this "size". If size of the requested data is greater than the block size, data is to be split into several blocks.
  8. ACK blocknum [client -> server] - acknowledge receiving block number "blocknum"
  9. ERROR commandname msg [server -> client] - respond on a command "commandname" server was no able to run
  10. OK commandname [server -> client] - respond on the command "commandname" server successfully run
all the commands are the pure text commands and supposed to be sent via the "control" connection. Via "control" connection we send only commands and server respond messages. All the data is to be sent via UDP "connection".

Client

When a client sends any command that requires data from the server (#1, 3, or 4) it has to open a UDP socket and read data from either the default port or from the port specified by the PORT command. When server receives one of these commands it has to start sending the requested data to the client's computer via on "data" connection port using UDP socket. At the same time it should respond over the "control" connection how many blocks of data will be sent. Each block of data has to have a unique ID. Once client computer receives a data block it sends an ACK via the control connection. If a client receives a block with the ID it expects (initially 0) it may write it on the disk, otherwise it should buffer it in memory. For example, if client gets packets with IDs 0, 1, 3, 4, and 5 it may write the first two on the disk, but has to buffer the rest of them. If after that the client gets packets with IDs 7 and 2, then it may now write 2, 3, 4, and 5 on the disk, but has to buffer 7.

Client also should provide some user interface to allow the user ask for a specific file or change settings. Please also display server responds to the user.

Server

Server can send several data blocks (a specific number [window size] depends on your settings) without getting them ACKed, but after the last block is sent server has to wait for all ACKs. once the ACK for the first block is received the server may send one more block of data. If an ACK for a packet is not received in a specific amount of time the server should retransmit the unACKed block.