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:
The client functions include:
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
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
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 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
for example, mine is called:
(as with hw#2).
4. write a
makefile that will automatically compile and link
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
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.
Follow the submission instructions.
(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).