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:
socket
connect
close
recv
- updated 1/29: use recv instead of readsend
- updated 1/29: use send instead of write
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.
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:
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.
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
select
. The extra credit will give you a 20% bonus to
your grade.
You will be graded on the following: