Program 4

TCP Card Dealer - select


After finishing program 3, you should now have a card dealer server that is using TCP to communicate with the clients. The next step is to replace the polling loop with something a little more reasonable. The next easiest alternative is to use the select() call.

You should read about the select call in the Unix Network Programming Manual. There are a number of other examples of using select that can be found with a little Googling, and I have several books in my office that have examples of using select.

NEW: I have a few pages out of a book that explains the select() call better than I have been doing - it might provide a little additional information. The pages are from Unix Network Programming, 1st Ed. by W. Richard Stevens. I also have similar info from the second edition of the same book. It has a litte more complete description of the conditions under which bits get set in the different fd_sets.

For this assignment, you need to modify your TCP card dealer server and from the last assignment to use select(). You should change out the polling loop for a select loop, modify how you handle the server and client sockets so that you also maintain the file descriptor bitmaps (fd_sets) used as input to select, and change the loop to correctly process events that are indicated by the descriptor sets returned by select.

Modify your server as specified - you can give it a new name, but everything else should work just as it did for the previous program. Once good thing is that you should not need to make any changes to the client program - the same client should be able to connect with the server for program 3 or program 4 (and the next two servers as well).

You should again do some design work before you start hacking away on code - make sure you know how you are going to manage your list of sockets, and how you will build the select fd_sets from this list.

Adding onto Your Code Library

You should continue to refine the library of socket functions - add routines to the server code that allow you to use select to manage a set of sockets on the server side. Clean up any code that might need it for both the server and client.

Assignment Submission

NO hard copy, please. Everything should be submitted via email by the due date - mail everything to Anthony. Follow Anthony's specifications for assignment submissions. You need to include the design, your source for the main application, your source for your library, and the output from your server for two different test runs. (You don't need to include any source for the client, since it should be the same as last time.) For the first test run, start the server with one deck and choose one of the ports designated for the lab (40000-40007). If your server can't open a socket on that port, try another one; you should succeed before you exhaust all eight possibilities. Start a client in another window and request twenty cards, shuffle, then request five more cards. For the second run, start the server with four decks, choosing the port as in the previous run, then start two different clients and request twenty cards from each. (These are the same test runs as you did for the last program.)

You should include the following:

The first item should just be in the body of the email - attach the design, source, and output as separate files.