Question: Introduction In this assignment, you'll be writing a program that downloads files from a server. You'll be putting together many of the concepts you have

Introduction
In this assignment, you'll be writing a program that downloads files from a server. You'll be putting together many of the concepts you have learned during the course.
Your program's job is to communicate with the server using a protocol of simple commands to fetch a file listing and download one or more files, saving them in your Theia workspace. However, the user is shielded from the underlying protocol and instead sees a user-friendly interface. It doesn't have to be fancy, but the user should not normally see the actual commands and responses being sent to/from the server.
The file server is running on the newark.cs.sierracollege.edu and london.cs.sierracollege.edu hosts, port 3456. The user should be able to pick which host to connect to. Each server has a slightly different set of files available to download.
Once connected, the user is presented with a menu of options:
List the available files
Download a file
Quit
The user can keep listing the files and/or downloading them until they select the option to quit.
Video Demonstration
The video here is a quick demonstration of what the client program you develop could look like.
The Protocol
The client program should make only one connection to the server, when it starts up, and keep that connection active until the program ends.
During the connection to the server, the client has a two-way "conversation" with the server in which it issues simple commands and receives responses in return. It will be important as you write your program to keep the client and server "in sync." The server is always going to wait for a request and send a response. Then it will cycle back and await the next request.
The client, likewise, should alternate between sending a request and receiving the response.
The file server accepts the following commands: HELO, LIST, GET, SIZE, HASH, PING, QUIT. When issuing commands to the server, be sure to terminate it with a newline. Otherwise, the server will wait indefinitely. All the commands are capitalized as shown.
All commands responds with either +OK or -ERR, indicating success or failure. Failure responses will be followed by a more descriptive error message. Success responses may be followed by additional data, as appropriate for each command.
Upon initial connection, the server will send the message +OK Greetings. The server will then await a command sent from the client.
The command format and responses for each command is detailed in the sections below.
HELO - The HELO command will respond with a random greeting in one of about a dozen languages. For example:
HELO
+OK Ciao. Piacere di conoscerti.
The command may be optionally followed by an identifier, such as your name or an alias. If included, the output will also include the identifier. This may be useful for debugging.
LIST- The LIST command will return a status message +OK and a list of the files available to download. Each line of the listing will contains the file size, in bytes, followed by the filename.
The listing is terminated with a line containing a single dot. Example:
LIST
+OK
4935 mydocument.txt
1248580 bigimage.jpg
125 smalldoc.txt
.SIZE - The SIZE command should be issued with a filename. It will respond with +OK followed by the size of the file in bytes. If the file doesn't exist or some other error occurred, it will respond with -ERR and an error message. Example:
SIZE mydocument.txt
+OK 4935
GET-
The GET command it used to retrieve the contents of a file. Provide a filename as an argument. The server will respond with +OK, then the contents of the file. No end-of-file marker will be provided; it is the responsibility of the client to stop receiving data when the file is complete.
Responds with -ERR and an error message if there was a problem.
Sample:
GET mydocument.txt
+OK 4935
...
contents of the file here
...
HASH---end the HASH command followed by a filename. The response will be +OK followed by the MD5 hash of the file contents, or -ERR if the file doesn't exist.
Sending the HASH command at least once in a session will also introduce errors in the retrieved files. There will be a 30% chance of having at least one bit in the file changed. If the HASH command is not issued, files will not have any errors in their contents.
You will not need this command unless you are implementing one of the additional features described later in this document.
PING- The only response to the PING command is +OK.
QUIT-- Used to close the connection from the server's end. The response will be +OK and then the connection will close. The client will need to close the connection from its end, as well.
both the client and the sever together as the user interacts with the program.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!