Class GameNetworkObject

java.lang.Object
  extended by GameNetworkObject
All Implemented Interfaces:
java.io.Serializable

public class GameNetworkObject
extends java.lang.Object
implements java.io.Serializable

This class is used by GameServer and GameClient to send data to each other across the Internet (like a packet). This class stores a single object as well as the protocol for communication. The protocol can may specify that a data object is being sent, which would indicate what kind of data, or it may specify a message without data. This class is used as a universal network packet object. If certain games would like to add more functionality by adding their own static variables, they should simply extend the class.

Author:
Adam Hauer
See Also:
Serialized Form

Field Summary
static int COLOR
          Protocol message type that the server sends to clients indicating their color
static int DRAW
          Protocol message type that the server would send to clients to inform them that the game has ended in a draw.
static int GAME_BOARD
          Protocol message type that the server would use to send the current game board to clients.
static int GAME_FULL
          Protocol message type that the server would send to clients trying to connect to inform them that there is no room for that client to connect.
static int GAME_INTERRUPTED
          Protocol message type that the server would send to clients to inform them that the game has been interrupted, most likely due to one of the clients disconnecting from the server.
static int GAME_RESET
          Protocol message type that the server would send to clients to inform them that the game has been reset, like at the end of a completed game.
static int MOVE
          Protocol message type that the client would use to send a move to the server.
static int PLAYER_PROFILE
           
static int START_GAME
          Protocol message type that the server would send to all clients to let them know the game has just started.
static int STATS
          Protocol message type that the server sends to clients telling them the current game stats
static int WINNER
          Protocol message type that the server would send to all clients to inform them that the game has been won.
static int YOUR_TURN
          Protocol message type that the server uses to send to clients indicating whose turn it is.
 
Constructor Summary
GameNetworkObject(int initType)
          Constructor to be used for network packets that will include messages, but no data.
GameNetworkObject(int initType, java.lang.Object initData)
          Constructor to be used for network packets that will include both messages and data.
 
Method Summary
 java.lang.Object getData()
          Accessor method for the data stored by this packet.
 int getType()
          Accessor method for the type of this packet.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

START_GAME

public static final int START_GAME
Protocol message type that the server would send to all clients to let them know the game has just started. No data would be sent with this type of packet.

See Also:
Constant Field Values

GAME_FULL

public static final int GAME_FULL
Protocol message type that the server would send to clients trying to connect to inform them that there is no room for that client to connect. No data is associated with this message.

See Also:
Constant Field Values

GAME_INTERRUPTED

public static final int GAME_INTERRUPTED
Protocol message type that the server would send to clients to inform them that the game has been interrupted, most likely due to one of the clients disconnecting from the server. No data is associated with this message.

See Also:
Constant Field Values

DRAW

public static final int DRAW
Protocol message type that the server would send to clients to inform them that the game has ended in a draw. No data would be sent in association with this message.

See Also:
Constant Field Values

PLAYER_PROFILE

public static final int PLAYER_PROFILE
See Also:
Constant Field Values

YOUR_TURN

public static final int YOUR_TURN
Protocol message type that the server uses to send to clients indicating whose turn it is.

See Also:
Constant Field Values

STATS

public static final int STATS
Protocol message type that the server sends to clients telling them the current game stats

See Also:
Constant Field Values

COLOR

public static final int COLOR
Protocol message type that the server sends to clients indicating their color

See Also:
Constant Field Values

GAME_BOARD

public static final int GAME_BOARD
Protocol message type that the server would use to send the current game board to clients. The data associated with this packet would be the latest game board as managed by the server.

See Also:
Constant Field Values

MOVE

public static final int MOVE
Protocol message type that the client would use to send a move to the server. The data associated with this packet would be the info specifiying the row & column of the cell chosen by that move.

See Also:
Constant Field Values

WINNER

public static final int WINNER
Protocol message type that the server would send to all clients to inform them that the game has been won. The data associated with this packet would be a String representing the player who won ("X" or "O").

See Also:
Constant Field Values

GAME_RESET

public static final int GAME_RESET
Protocol message type that the server would send to clients to inform them that the game has been reset, like at the end of a completed game. A brand new game board would be sent as data with this packet.

See Also:
Constant Field Values
Constructor Detail

GameNetworkObject

public GameNetworkObject(int initType)
                  throws java.lang.IllegalArgumentException
Constructor to be used for network packets that will include messages, but no data.

Parameters:
initType - - the type of message represented by this object.
Throws:
java.lang.IllegalArgumentException

GameNetworkObject

public GameNetworkObject(int initType,
                         java.lang.Object initData)
                  throws java.lang.IllegalArgumentException
Constructor to be used for network packets that will include both messages and data.

Parameters:
initType - - the type of message represented by this object.
initData - - the data stored by this object packet.
Throws:
java.lang.IllegalArgumentException
Method Detail

getData

public java.lang.Object getData()
Accessor method for the data stored by this packet.

Returns:
- the data stored by this packet as an Object. To use this data, one must cast it to its correct type.

getType

public int getType()
Accessor method for the type of this packet.

Returns:
- the type of this packet, which must match one of the protocol constants.