CSE 132 (Spring 2009)
Studio 9: Multiuser Game Server

  1. Download and install this zip in a new Java project in eclipse.
  2. BlockingQueue
    1. Work on the BlockingQueue class so that it properly uses wait and notifyAll to accomplish its goals. Do not spin, but loop with a wait inside.
    2. Run the BlockingQueue as a Java Application and make sure that all 20 integers (0...19) are enqueued and dequeued without problem. You should see the program pause initially, then enqueue 10 objects quickly, then as each object is dequeued a new object should get enqueued.
      Have the professor or TA check your work here. If you had problems with the midterm on question 2, you will want to submit a discussion of this object and its behavior (watch for this on the course home page), so be sure you understand things before you leave studio.
  3. ConsoleHandler: take a look at this class and see how it intends to interact with the GameController class.
    Add code so that if somebody enters die die die, the shutDown method of the game object is called.
  4. Server: In the run() method, write code that:
    1. Establishes a ServerSocket at the specified port.
    2. Continually (infinite loop) accepts a connection from the ServerSocket, constructs a new PlayerHandler for the resulting Socket and the game, and .start()s the PlayerHandler.
  5. PlayerHandler: this class is responsible for handling the actions of the player. It is this class that along with the client code must determine the protocol of how the client and server interact.

    Complete the code as directed by the comments in the code.

    Some help:
    • If you have a DataInputStream object, you can call readUTF() on that object to read a Java String.
    • Look at how the code handles any exceptions. You can always throw an Error if you want the code to stop.
    • Be sure you understand just how the try...catch...finally code works, especially if you had trouble on the midterm.
  6. At this point you should be able to run GameController as a Java application and see the server working with the simulated clients and with the ConsoleHandler. The ConsoleHandler pops up a box into which you can type messages that are passed along to the game.
  7. GameController: complete the showPlayers method so that it displays a list of the current players, as you saw in class today.
    Do not do the work directly! Instead, use addRunnable to queue up the work for the server to perform.
  8. Done!
    Demo your work (run GameController as a Java application) to the TA or professor and get checked off for the studio sheet.


Last modified 20:11:06 CST 11 January 2010 by Ron K. Cytron