Programming Assignment 2

Objective

The objective of this assignment is to familiarize yourself with the socket API, TCP, and different strategies for client/server implementations.

Assignment: Client-Server Programming

The idea is to create a calendar server based on TCP. You need to define a protocol (i.e., define how messages are formatted and transmitted), implement it, and write a client and a server that communicate using your new connection-oriented protocol. Your protocol should support the following functionalities:

1. Add a new calendar event.
2. Remove a calendar event.
3. Update an existing calendar event.
4. Get the events for a specific time or time range.

There are no other requirements regarding the protocol, i.e., you are free to decide the protocol details, e.g., the message structure and content for the client/server communication.

Client Implementation

The client is a simple program that takes several arguments and contacts the server and prints the response received from the server. The syntax for the client should be:

A: Adding an event: ./mycal hostname port myname add 031505 0800 0900 Exam
B: Removing an event: ./mycal hostname port myname remove 031505 0800
C: Updating an event: ./mycal hostname port myname update 031505 0800 1000 OralExam
D: Getting an event 1: ./mycal hostname port myname get 031505 0800
E: Getting an event 2: ./mycal hostname port myname get 031505

In all cases 'myname' is a string that identifies a user (e.g., login name). In (A), you specify the date, the beginning and end time of the event, and a single word identifying the type of event (e.g., exam, doctor, trip, meeting, ...). You can assume that no event can go beyond 2400 of the same day (i.e., every event has to be finished by midnight at the latest). If there is a conflict with another already stored event, the client will be notified by the server and the client informs the user (e.g. "Conflict detected!"). In (B), you specify the date and the beginning time of an event, if successful the client will receive an acknowledgment from the server, if the event does not exist, the client will be notified by the server and the client informs the user. In (C), you specify an event as in (A), however, either the ending time or the event type has to be different (or both). Again, the client will inform the user if the operation was successful. In (D), the server returns the type of the event requested, if the event does not exist, the client informs the user. Finally, in (E), if only the date is specified, all events of that day are returned.

Further, the server's hostname and port number have to be passed to the client as command line arguments.

Server Implementation

The server waits for requests from clients. Each user's ('myname') events are stored separately from other users (either in a data structure or a file, e.g., 'myname.cal'). If files are used, the file should be created when the first event is set and should be deleted when the last remaining event is deleted or expired. You are required to provide three different server implementations:

Error Handling

The following error handling is expected: all return values of the system calls have to be checked, also check the correct number of command-line parameters for the client and the correct date and time format (also make sure that the end time of an event is later than the begin time). Whenever the server responds to a request, it should also remove ALL expired events for ALL users. Compile your code with the '-Wall' flag and make sure to remove all warnings.

Evaluation

Run your program for the following scenarios (in the given order):

./mycal steve add 031509 0900 1100 Test1
./mycal steve add 031509 1300 1400 Meeting1
./mycal steve add 031509 1600 1830 Class
./mycal tim add 031509 1500 1630 Class
./mycal tim add 031609 1500 1530 Seminar
./mycal steve add 031609 0800 0930 Dentist
./mycal tim add 031509 14.30 15.30 Gym
./mycal tim remove 031509 1500
./mycal martin add 031709 0900 1130 Shopping
./mycal steve update 031609 0800 1000 Dentist
./mycal tim add 031709 0900 1200 Squash
./mycal martin update 031709 0800 1130 Shopping
./mycal tim get 031609 1500
./mycal martin get 031709 0800
./mycal steve get 031509

Provide the output of your client program for this input sequence in your 'readme' document. Write one script that contains the input sequence described above in the correct order. For the second and third server implementation, provide an additional script with the same sequence plus an additional command using the "getall" operation for each of the users in the example (steve, tim, martin). Provide the client output for EACH server implementation. If you use files to manage events, make sure to remove all client files before you start a server (or let a server remove the files for your automatically when you stop a server).

Add the output of these scenarios to the evaluation part of the README document (for all server implementations). If you made any specific assumptions or encountered problems or have unresolved issues, mention them in the document.

Submission

The due date for this assignment is March 3rd, 2009, 11am EST. You will use the drop-off boxes (you will find a box with your login name). Make a directory called "project2" and place all required files into this directory (either individually or as one tar file). The required files are: all source files, a Makefile, run scripts for the required test cases, and a document called README (ASCII file) or readme.ps or readme.pdf (postscript file), which contains a project summary, your solution approach, a description of your protocol implementation, any encountered problems and how you solved them, any unresolved issues, an evaluation with the output of the program for the test cases mentioned above (for all server implementations), and a usage explanation.