vooga.engine.networking.client
Class ClientConnection

java.lang.Object
  extended by java.lang.Thread
      extended by vooga.engine.networking.GameSocket
          extended by vooga.engine.networking.client.ClientConnection
All Implemented Interfaces:
java.lang.Runnable

public class ClientConnection
extends GameSocket

Basic class for connecting to the server from the client and sending and receiving data. Works for basic games but can be extended to add more complicated functionality. Override the getData() method to deal with receiving messages from the socket and the sendData() method for sending messages to the socket.


Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
 
Fields inherited from class vooga.engine.networking.GameSocket
outStream
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
ClientConnection(java.lang.String name)
          Calls GameSocket constructor with the server's IP address and the port.
 
Method Summary
 java.lang.String getData()
          Listen for incoming data for the game.
 void sendData(Serializeable data)
          Send a Serializeable object over the network.
 void sendGameOver()
          Tell the server that the game is over.
 
Methods inherited from class vooga.engine.networking.GameSocket
closeConnections, finalize, isConnected, receive, run, send
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ClientConnection

public ClientConnection(java.lang.String name)
                 throws java.net.UnknownHostException,
                        java.io.IOException
Calls GameSocket constructor with the server's IP address and the port. The port is based on the name of the game since each game has a different port that it operates on.

Parameters:
name - the name of the game you're trying to connect to and from
Throws:
java.net.UnknownHostException
java.io.IOException
Method Detail

getData

public java.lang.String getData()
Listen for incoming data for the game. If the data is null then return gameOver otherwise just return the data String.

Returns:
data that was sent over the network

sendData

public void sendData(Serializeable data)
Send a Serializeable object over the network. Calls the Serializeable object's serialize method to convert it to a String to send to the socket.

Parameters:
data - the Serializeable object sent over the network

sendGameOver

public void sendGameOver()
Tell the server that the game is over.