Homework 3 : Networked Applications with GUI Interfaces

GUI clients for networked applications face a unique challenge: they have to monitor a network connection for input from the remote peer and update the GUI when a remote message is received. The GUI thread cannot be used to monitor the network because blocking network reads make the GUI thread unresponsive. This means that network monitoring must be done in a separate thread created for that purpose. However, the network input monitoring thread cannot update the GUI because GUI components must be updated from the GUI thread. The solution is to have the network monitor thread post a work order to be run later by the GUI thread.

In this assignment, you will write a networked application that has a GUI to gain some experience with how networked GUI applications are designed and written. The application is a networked Tic Tac Toe game that uses a JavaFX interface for its GUI.

The Tic Tac Toe GUI

The GUI looks like this

Initially the application Networking Role menu is enabled and the Game menu is disabled. One of the users must select the server role , and another user must select the client role. Selecting the client role will pop up the following dialog

The user who is the client enters the IP address of the server, which is assumed to be running at port 50000. At that point the client will connect to the server and the two participants can begin to play.

Game Rules and Networking Protocol

The Game menu has two menu items: Play Again and Exit. The Play Again menu item is disabled while the game is in progress, and it only becomes enabled when a game is over. At this point, either of the players can select the Play Again item to send a request (Protocol message playagain query) to the remote side to play another round. The arrival of a request to play again will cause a dialog to pop up asking the user if he or she wants to play again:

If the remote player agrees to play again, the remote side returns a playagain consent message, which causes this dialog to pop up:

If the remote player does not wish to continue playing, a playagain deny message is returned, which causes this dialog to pop up:

Also at any point while the game is in progress, a player can select Exit on the Game menu to quit the game. This results in an exit protocol message being sent to the remote side. After sending the exit protocol message, the ending side can exit the program.

The reception of the exit message causes the dialog

to pop up. The game exits when the user dismisses this dialog box.

The server player is assigned "X" as the player id, and the client is assigned "0". The server movers first for the first game. Thereafter, the two players take turns as to who gets to move first when a new game is started.

Here is a summary of the protocol commands used in the game. Further details on the protocol can be found in the TTT.zip code skeleton provided to get you started.

        move row col
        chat message
        playagain query
        playagain consent
        playagain deny

Make sure you read all the comments in the provided skeleton because they provide additional information on how this should be implemented.

Due Date

Monday of Week 7.