Fall 2002
Homework #3
due Mon Oct 28, by 6AM (electronically)

The goal of this assignment is to learn how to write multiple processes in C that communicate with each other via stream sockets using TCP. This assignment is worth 15 points (out of 110 this semester). Distribution of points is indicated below.

So far this semester, you've been building a single player educational game involving one user who communicates with a computer program that operates within a single process. By the end of the term, the game will involve two players interacting with each other over the Internet. With the current assignment, you will take another step towards this final implementation by making the game into a two-process program.

So, your job with this assignment is to take the game as you built it for homework #2 and divide it into a "server" process and a "client" process. The "server" will handle interactions with the data file. The "client" will handle interactions with the user.

For example, in my simple flashcard program, the server functions include:

  1. validating the user's login name and password when s/he starts running the game,
  2. selecting a flashcard to present to the user,
  3. validating the user's response to the flashcard and assigning a score to the user's response, and
  4. recording the user's response and score.
Your server process will loop from step 4 back to step 2, until the user quits playing the game.

The client functions include:

  1. prompting the user to enter his/her login name and password,
  2. sending the login name and password to the server for validation,
  3. reading a flashcard from the server and presenting that to the user,
  4. reading the user's response to the flashcard,
  5. sending the user's response to the server,
  6. reading the user's score from the server and showing that to the user.
Your client process will loop from step 6 back to step 3, until the user indicates that s/he wants to quit playing the game -- at which point the client process will terminate. Your server will catch this "death of child" signal and will also terminate (after saving the game data in your data file).

You should base your client/server process model and socket communications on the echo.c program described in class. You should integrate that code with the "play" portion of your game from hw#2.

WARNING! socket handling is slightly different between Linux and SunOS, so you are STRONGLY encouraged to develop your code on the CUNIX system.

FIRST, print out the timesheet and keep track of how much time you spend doing the tasks outlined below.

1. design.(3 points: 1 point for server, 1 point for client, 1 point for the diagram)
As usual, you need to begin with a design document. Include in the design document a description of the functionality of each process as well as the data you are going to pass between the server and the client, and how you are going to store it in each process. Note that you MUST have different instantiations of the data structures for the client and the server.
Your design document should include a diagram of the flow of data between the client and the server. It is okay if this diagram is hand-written (i.e., you don't need to spend hours with a drawing program to do this diagram).
If you make any changes to the game as described in your first two homeworks, you must document these changes here.
The documentation should be 1-2 pages, 10-point font. It must be complete -- so you need to be CLEAR and CONCISE. You MUST print out the documentation and bring it to class on the due date.

2. instantiate your data structures.(2 points: 1 for server, 1 for client)
You will use the data structures that you defined in hw#2. But you MUST have different instantiations of them in the client and in the server.
If you start with the echo.c example from class, this means you need to declare and allocate memory for the data structures within both your equivalents of the echo_server() and echo_client() functions.

3. write a server and a client.(7.5 points: 1 point for programming style, 1 point for handling system errors, 1 point for handling user errors, 2 points for the server functionality, 2 points for the client functionality and 0.5 points for data flow functionality)
You need to divide up the code for your game so that you have a server process and a client process, with the functionality as described above. Here is what the program should do:

You can decide how frequently to send usage and performance data back and forth between the client and the server. You can also decide how frequently the server should write to the data file. But you should design your program so that it is robust. That is, if a process crashes in the middle or the socket connection is lost, then you should minimize the amount of game data that is lost. A really robust program would be able to store a partially completed game and let the user continue from where s/he left off if s/he restarts an interrupted game.

You need to handle errors elegantly. These include both system level errors (anything from the inability to make a socket connection to the inability to read from or write to the data file) as well as user errors (i.e., invalid inputs).

Your code must be modular, clearly indented and documented. The TAs should have been giving you comments on the previous two assignments about your programming style. If you are unclear about this, then follow the style I've used for examples in class. You should have a header comment at the top of each file and a comment at the beginning of each function describing (1) the functionality of the function, (2) the inputs to the function and (3) the outputs of the function (which include return value, arguments modified -- if passed as pointers, and global data modified).

You MUST name the game play-<your-cunix-id>.x, for example, mine is called: play-eis2003.x (as with hw#2).

4. write a makefile.(2 points)
Write a makefile that will automatically compile and link the program.
You can start with the makefile that accompanies the video example shown in class.
You should create a library that contains your equivalent of the profile.c (i.e., helper file(s)) from hw#2.
You MUST name the file makefile.

5. submit.(0.5 points)
You need to submit your program in two ways: electronically and hard copy. There is no partial credit here -- if you don't follow the submission instructions, you lose all the points for this section.

  1. electronically
    Follow the submission instructions.
  2. hardcopy.
    (1) Print out the homework template cover page and fill it out.
    (2) Print out the timesheet and fill it out.
    (3) STAPLE the cover page, timesheet and hardcopy of your documentation together.
    (4) Make sure your name and CUNIX ID are on all the papers you hand in!
    (5) Bring all this to class on the day the assignment is due and deposit it in the homework box at the front of the classroom within the first 5 minutes of the class (by 1.15pm).