In
this project, you are to develop a simple client and a simple server.
The client should establish a TCP
connection
with the server. Once the connection is established, the client should
send
a "ping" message (described in Section II.a)
to the
server. Upon receiving the "ping" message, the server should reply with
that same message, i.e. a "pong", immediately. The client waits for the
reply, then repeats the message exchange for a total of N such
exchanges, then closes the connection. The client should
measure the latency of N such transactions and report the total time
and
average round-trip time and then terminate. In addition to responding
to your "ping-pong" client's messages, the server should have an
alternate execution mode in which
it acts as a simple web server. This functionality is described in Section III. Your server must be able to handle
multiple concurrent connections from clients.
The ping-pong client should take 4 command line parameters, in the following order:
The host where the server is running. You should support connecting to hosts by domain name (e.g. forest.mpi-sws.mpg.de).
The port on which the server is running (e.g. 4321).
The size in bytes of each message to send (e.g. 50).
The number of message exchanges to perform (e.g. 10).
The server should take 1 mandatory parameter and 2 optional parameters, in the following order:
The port on which the server should run (e.g. 4321).
The mode of the server. If this is "www", then the server should run in web server mode (described in Section III). If it is anything else, or left out, then the server should run in ping-pong mode.
This is the directory where the web server should look for documents. If the server is not in web server mode, ignore this parameter. (e.g. /home/student/comp429/project1/html)
The ping packet is formatted as follows:
size (4 bytes) | data (size bytes) |
The server should reply with the exact same message.
When the server's optional mode parameter is set to "www", the server should run in web server mode. In this mode, the server should answer HTTP GET requests from web browsers. The server should open files relative to the root directory specified as a parameter to the server, in order to respond to GET requests. The full specification for HTTP can be seen at http://www.w3.org/Protocols/. Because HTTP is an extremely complicated protocol, we only expect you to implement a subset, described here.
Note that you
want all requests to be restricted to under the root directory. This
means you should disallow requests containing "../" path elements which
could potentially cause the server to send documents not under the root
directory. You can allow symbolic links which leave the specified root,
since the user explicitly put them there and knows what to expect.
Return error message with code 400, if "../" appears
in the path.
If a file is not
found, you need to return an appropriate HTTP error code and message.
How you handle directories is largely up to you; you can return a
file-not-found message, a more specialized error message, or convert
the request to index.html within the specified directory. It is NOT
OK to just open the directory as a file and return the contents.
This project is due on Wednesday, May 16, 2005 at 11:59pm. To submit the project, create a single compressed file of your project directory (use tar and gzip), name it with the following format proj1_lastname (e.g. project1_gummadi.tgz), and send it by e-mail to the course staff at datanets-projects@mpi-sws.mpg.de.
In the project directory, there should be a file entitled README which documents how you tested your client and server, any known problems, and anything the graders should know. You should use make to build your project (there should be a Makefile in the project directory, and running make in the project directory should build both the client and the server). The grading will be done by testing how well your code runs on the student computer pool (CIP) machines, so make sure that your code works on these machines.
You can write your programs in C, C++, or Java. When programming in C++ and Java, you should not use certain advanced classes and libraries (e.g. Java HTTP library) that make your implementation trivial. If you have questions regarding this, approach the course staff during their tutorial or office hours. Don't forget to check for error return codes to network API calls; it's not only good practice, it can also help you to figure out what is going wrong if your program is not doing what you expect.
The Hypertext Transfer Protocol (HTTP) is an application-level protocol for distributed, collaborative, hypermedia information systems. HTTP has been in use by the World-Wide Web global information initiative since 1990. The first version of HTTP, referred to as HTTP/0.9, was a simple protocol for raw data \ transfer across the Internet. HTTP/1.0 improved the protocol by allowing messages to be in the format of MIME-like messages, containing meta information about the data transferred and modifiers on the request/response semantics. Latest HTTP Version is 1.1, which is documented in RFC 2616; version 1.0 is docume\ nted in RFC 1945.
HTTP operates over TCP connections, usually to port 80, though this can be overridden and another port used. After a successful connection, the client transmits a request message to the server, which sends a reply message back. HTTP messages are human-readable.
The simplest HTTP request message is GET url, to which the server replies by sending the named document. If the document doesn't exist, the server will send an error message stating this.
The format for GET command is GET url HTTP/version. The client may then send additional header fields, one per line, terminating the message with a blank line. The server replies in a similar vein, first with a series of header lines, then a blank line, then the document proper.
Client sends HTTP request:
GET /index.html HTTP/1.1\r\nServer replies with HTTP response:
HTTP/1.1 200 OK\r\nNote: (a) The line-feeds \r\n and the empty line between HTTP response header and HTTP response body are mandatory. (b) All message characters should be encoded in ASCII.
As there are many extensions to HTTP and HTTP itself is rather complex, we require you to implement at least the following subset of HTTP/1.1
Many more tutorials can be found on the web for every possible programming language. Just ask your favorite search engine.