Home Announcements Schedule Assignments Project Reading Reviews Resources

libmicrohttpd Checkpoint 1: Implementing a simple web client

Due: Feb 4th, 2008

In this project you will learn basic socket programming using TCP to send HTTP 1.1 messages to a web server. From the client perspective, you need to understand how to use:

Documentation for socket and connect can be found in the Unix man pages. The man pages are accessed on the linux machine by using the man call. For example, to find documentation on socket, you would execute the command: man 2 socket. The 2 here specificies that we are looking in section 2, which is the programming section.

Getting Started

Start by downloading http_client.h. This file defines a few functions that are required by this project. You must create these functions as they will be graded in the project. The header file describes what each function should do, so read there for further details.

Your project needs to take three command line arguments:

  1. The site to connect to
  2. The port number to connect to
  3. The file to retrieve (for example, index.html)
  4. The number of iterations to retrieve the file
  5. Whether or not to print the output to the screen, 1 = YES, 0 = NO

When you run your program, it should allow you to give it the arguments and it should open the connection to the given site, retrieve the file by executing an HTTP GET command, and then close the connection, repeating the last steps by the number of iterations specified.

Output

The retrieved files should only be outputted if the 5th command line argument is 1. In addition, you need to add timing code to see how long it takes to perform all the iterations. When you execute your project, it should state the site, port, file, number of iterations, and how long it took to execute all of the iterations.

The following code will define a function for you that will count clock cycles, called rdtsc(). You can call this to determine how many clock cycles have passed since the machine was booted. By using the difference between when you started the calls for GET and when you finished, you can measure the timing of your application's execution. Note that these functions returns uint64_t, which are 64-bit integers, so store them appropriately.


#if __i386 || x86_64
static __inline__ uint64_t rdtsc() {
  uint64_t x;
  __asm__ volatile ("rdtsc" : "=A" (x));
  return x;
}
#elif __amd64
static __inline__ uint64_t rdtsc() {
  uint64_t a, d;
  __asm__ volatile ("rdtsc" : "=a" (a), "=d" (d));
return (d<<32) | a;
}
#else
#warn rdtsc not available for your platform
static uint64_t rdtsc() {
  return ctime();
}
#endif

Extra Credit

For extra credit, you can parallelize your calls for a large performance increase. You may use either threads (see pthread_example) or select. The extra credit will give you a 20% bonus to your grade.

Graduate Students

This project is only for the undergraduate students. Your project is completely different, so don't do this one! For your project, visit the grad project page.

Grading

You will be graded on the following: