CSE 532 Spring 2008


Lab 1: "Reactive Card Game"

Points: 10% of final grade

Teams: declared or assigned by 11:59pm Sunday February 16, 2008

Submitted: by electronic submission to cse532@cec.wustl.edu

Due: by 11:59pm Sunday March 2, 2008 (Note the New Deadline)


Purpose

The purpose of this assignment is to introduce the basic ideas of reactive concurrency, of active and passive connection establishment, and of service handling. In this assignment you will again use the basic wrapper facades for networked OO programming provided by the ACE framework, that you used in the previous lab. You should also use algorithms, containers, iterators, and functors from the STL to simplify the programming of this assignment. In this lab we will focus on integrating the Reactor with the Acceptor and Connector in ACE, to allow cards to be dealt to each client by a server, and for clients to score their hands and send the scores to the server who will declare a winner (or a tie). We will use these ideas and the design and implementation skills you'll develop using them, repeatedly throughout the rest of the semester.


Assignment

In this assignment you will modify your Lab 0 server and client programs so that each client can be connected to multiple servers, as well as maintaining the feature from the previous lab that each server can be connected to multiple clients. All clients and servers will play the same kind of card game (5 card stud poker) but each server will run its own game instance (or instances, differentiated by game names)

The connection semantics of your client and server programs will be similar to those in Lab 0. Servers should again be started first and should listen passively for connections from the clients. Each client should initiate a separate connection to each server that is listed in a client definition file that is specified when the client is started, and keep each connection alive until it is closed down by the server on the other end or until the client itself is shut down. A new key feature of both servers and clients for this lab, is that they should be able to manage multiple connections at once reactively.

To do this, please change both the servers and clients from your Lab 0 implementation to use the reactor and acceptor/connector patterns so that each can react to events on multiple ports at once. Each server should be able to respond to events on its established sockets and the port on which it's listening for new socket connections, for arbitrary patterns of arrival of those events. Similarly, a client should not wait for each server to respond to its connection initiation requests, but rather should send connection requests to all of the servers specified in its client definition file as quickly as possible, and wait reactively for connection completion events to occur, and register and operate service handlers for established connections even while it waits for any remaining connection establishment requests to be completed.

These requirements mean that both the acceptor on the server side, and the (possibly multiple) connector(s) on the client side, should be registered as handlers in a local reactor. The acceptor and connector(s) should create separate service handlers for each connection they establish, and should also register each such handler with the local reactor. The overall picture is that all concurrency is managed within a single thread in each server or client process, using the reactor to multiplex events from a number of sources onto that thread.

To do this please perform the following tasks:

Servers

Clients


Resources

There are a number of resources available that can greatly ease your task in completing this assignment. This project is designed to be very straightforward if you study (and use) the Wrapper Facades mentioned in this section, and will be much more difficult if you do not.

Also, there are several more mundane (but as in any software project, important) areas where you can exploit tools and examples to greatly speed your progress on this project and the ones later in the semester. In particular, code fragments and Makefile examples are provided as exemplars to follow or discard, as you choose.

Wrapper Facades

The following Wrapper Facades are provided by the ACE version installed on the CEC Linux machines at /home/cec/class/cse532/ACE_wrappers/ace/ and are highly useful for this assignment:

The Reactor and Acceptor/Connector pattern implementations in ACE are discussed in detail in chapters 3, 4, and 7 of the C++NPv2 book:

EXTRA CREDIT:While you should at a minimum document your design decisions for particular issues requested in the assignment itself, labs that do a particularly thorough job of noting the important design issues, the alternatives that were considered but not done, the factors that affected each decision that was made, and how each such decision worked out, will be awarded additional points (up to 5 out of a total value for the assignment of 100).

Makefile & Environment

The GNU C++ compiler (g++) is installed on the CEC Linux machines. You will need to set a few environment variables (it may be convenient to keep these in a small script file and/or simply set them in your .cshrc or .bashrc file):

setenv ACE_ROOT /home/cec/class/cse532/ACE_wrappers
setenv LD_LIBRARY_PATH ${ACE_ROOT}/ace:${LD_LIBRARY_PATH}

You will need a Makefile that links appropriately with the ACE libraries and include files. Please feel free to adapt or use the following example Makefile.


What to Submit

README

When you have completed your program, please document your solution in a text file called README.

The first section of your README file should include:

  1. the number of the lab (e.g., "CSE 532 Spring 2008 Lab 1")
  2. the names and e-mail addresses of all team members
  3. an overview of how your programs are designed,
  4. the Wrapper Facades you used or extended and how they helped in your design and code, and
  5. any insights and questions you encountered while completing the assignment (including the design decisions discussion for which extra credit will be considered).

The second section of your README file should provide detailed instructions for how to:

  1. unpack your files,
  2. build your programs, and
  3. run your programs.

Please indicate any and all environment variable settings, etc. you are assuming will be needed for this. I should be able to receive your e-mail, and unpack, build, and run your programs using only the instructions in your README file and the tools available on the CEC Linux machines.

Electronic Submission

Please submit by e-mail to cse532@cec.wustl.edu a single file containing:
  1. your source code files,
  2. your Makefile,
  3. any example files you think useful (for example, a copy of the NW_servers.txt file showing the format you chose), and
  4. your README file.

You can use the uuencode, tar, and zip or gzip tools to do this, as in the provided example Makefile.

Please send a separate copy of your README file, with clear instructions on how your submission file was produced and how to unpack it using tools available on the CEC Linux machines.


Grading

Please treat this assignment as you would a commercial or research product that you are shipping to a large set of customers. Please take the time to test, document, and check your work to make sure all parts are shipped, and are of high quality. Grading will focus both on the quality of your solution and on the quality of the product itself, as it arrives at the cse532 account. To ensure the best possible result (and accordingly the highest possible grade), please pay attention to the following issues:

Correct Compilation and Operation

Your program must compile and run correctly on the CEC Linux machines using the Makefiles and source files you provide. Please make sure your program compiles without warnings, and you might even want to try different compilers and fix all the warnings for each. Problems with Makefiles will be handled similarly to missing files, with a 5 point deduction if you need to supply a new Makefile in order for me to build your solution on the CEC Linux machines.

Design Quality

Design decisions are largely yours to make, and as long as the design is concise, coherent, consistent, and addresses all design forces in the assignment, you will receive full credit. One key area to consider is whether each abstraction in your design does a single job, does that job completely, and collaborates appropriately with other abstractions. Minor deductions (1-3 points, but please be aware minor deductions can add up) will be made for abstractions that are unnecessarily large or have inappropriate inter-dependencies. Major deductions (5-15 points) will be made for larger problems like neglecting key design forces in the assignment.

Implementation Quality

How you implement your solution is again up to you, and I will take into account different approaches to implementation. Minor deductions will be made for things your program gets away with but are not good, like neglecting to check the return value from a system call or Wrapper Facade method (i.e., the program may have problems under special conditions) or calling exit(1) from inside a class method rather than providing a clean termination path, while major deductions will only be made for problems that produce incorrect or extremely inefficient behavior of the program. The former kinds of errors should be eliminated during your coding and code review phases, and the latter kinds of errors should be eliminated during your testing phase.

Coding Style

Different coding styles will also be accepted, as long as they are clear, readable, and consistent. Please code clearly with both the reader of the code and the user of the program in mind. Please use consistent indentation and placement of braces, and comment your code thoroughly. Use whitespace liberally - it's free and it makes it a lot easier to read your code. When grading, I will add tagged comments to the code indicating areas where I found particular issues to mention, whether or not points are deducted. Only minor deductions will be made for each style issue, except in extreme cases.

Documentation

Please make sure you provide adequate instructions on how to unpack, build, and run your program. Also, please make sure to document your solution. Minor or even major deductions will be made for inadequate explanation of how your solution does what it does, how you made key design choices, or how the user (or grader) can successfully build and run your program. Even if how you did something is obvious to you, please assume it is not obvious to the reader.

Missing Files

Missing files in the delivered software make it difficult or impossible to evaluate your solution. An automatic 5 point deduction will be applied for each missing file that is submitted later on request.

Late Submission

Labs submitted within 24 hours of the deadline will be graded with an automatic 10 point deduction. Labs submitted more than 24 hours after but within 48 hours of the deadline will be graded with an automatic 20 point deduction. Labs submitted after 48 hours from the deadline will not be graded except in extreme cases of extenuating circumstances. If you are running late completing the assignment, please let me know about the trouble as soon as possible, and please turn in as much as you can before each deadline so I can give at least some credit for the work you have done.

Grading Issues

Please avoid the following practices, for which I have made comments and possibly deductions in previous semesters, depending on the extent of the issue: Please use the following practices to improve the clarity and quality of your code and documentation: