CS 580 Client-Server Programming

Spring Semester, 2006

Assignment 2

Assignment Index

© 2006, All Rights Reserved, SDSU & Roger Whitney

 San Diego State University -- This page last updated 2/2/06

Assignment 2

You will be writing a small client-server system. The system is motivated by page counters for web pages, where one keeps track of the number of times a web page has been accessed.

The protocol for the system is as follows. The client can send two commands to the server: "count" and "reset". The format for the count command is:


where "<sp>" represents the space character and url is any string that does not contain "<sp>;". The server's response is:


where "n" is the number of times the count command has been called, without reset, for the given url and "ISO-8601Date" is the date of the first time count was called, or the first time after the last reset for the given url. The date is in ISO 8601 standard format . Some web pages track both the number of time the page has been accessed and when the page was first accessed (or created). Each time the count method is called with the same url the count increases by 1 and the date remains the same, except after a reset on that url. The server closes the connection after sending the response.

The format for the reset command is:


This will reset the count and date for the given url. The next time that count is sent with this url the count returned will be 1 and the date will be the date of that count command. That is after this command the server will act as if it has never seen this url. When a web site is redone, one may wish to reset the page counters. This command allows one to do this. The server response is:


The server closes the connection after sending the response.

If the server receives any request not described above it responses with


and then closes the connection.

Sample Interactions

Client Request

Server Response

count /foo ;

1 2006-2-2 ;

count /foo ;

2 2006-2-2 ;

count /bar/foo ;

1 2006-2-2 ;

The Assignment

Part 1 Write a client that has at least two public methods: count and reset. Count has one argument, the url that we wish to get a count for. The method returns two values: the count and the date. The reset method has one argument: the url we wish to reset. Write a server that implements the protocol. The server does not have to store the count values on disk. That will be a later part of the assignment. Note that while the assignment is motivated by web page counters we will not use it in web pages.

Part 2. Add logging to your server. Log each request. Also read setting for your server from command line and a configuration file.

Part 3. Use threads to allow your server to handle more than one request at a time.

Part 4. Modify your server to use a database to store the count and data information associated with each url.

Due Dates

Part 1. Feb. 9

Part 2. Feb 14

Part 3. Feb 21

Part 4. Feb 28

Just for Fun

1. Restrict your server so that it only response to clients from certain IP addresses. At one point web counters were commonly used, but few people could implement them. As a result after viewing the source of your page many people would start to use your counter. As a result page counters started to restrict which clients could use the counter.

2. Write a port scanner. That is a program that given a machine will return a list of ports that are open (that is have servers listening on that port) on the machine. If you know TCP/IP well write the port scanner so that the remote machine will not log the access to its ports.