Your job is to write a web client that tests web servers. Your client should take two arguments: a host and a file or directory on that host. For example, if your client is called downloader, it should run like this:
downloader www.nmu.edu /
Your client should output the following information about the file on the host.
Print All of the metadata from that file.
Save the contents of the URL to a file. Be sure not to include the metadata.
It should work on pictures. That means your data cannot be strings. An example picture can be foun at http://euclid.nmu.edu/~mkowalcz/kowalczyk.jpg and it should be 2524 bytes long. Another can be found at http://euclid.nmu.edu/~rappleto/Me/lori-mark-randy-airplane.JPG. It should be 110,365 bytes long.
Sending the Command
Send the command
GET / HTTP/1.0\r\n\r\n
Replacing the ‘/’ with whatever URL they chose.
Separating the Metadata from the Data
Read the whole download. At some point there will be four bytes ‘\r\n\r\n’. Everything before these bytes is metadata. Everything after is URL contents. Print the first, and save the second to a file.
Error Detection
The first line will always be “HTTP/1.0 200 OK \r\n” or something similar. The 10th, 11th, and 12th bytes should be a ‘2’, a ‘0’, and a ‘0’.
Points |
Task |
Task # |
10% |
Can make a socket to the server based on the command line args |
1 |
40% |
Can download and print metadata |
2 |
40% |
Can download and save to a file the URL contents |
3 |
-10% |
Each missing network call error check |
4 |
10% |
Can detect if it's a 200 OK |
4 |
-30% |
Only works on text files |
4 |
-20% |
File is the worng size |
4 |
0.0003 |
Plays a sound upon connection |
12 |