vooga.engine.networking
Class GameSocket

java.lang.Object
  extended by java.lang.Thread
      extended by vooga.engine.networking.GameSocket
All Implemented Interfaces:
java.lang.Runnable
Direct Known Subclasses:
ChatConnection, ClientConnection, TicTacToeConnection

public class GameSocket
extends java.lang.Thread

Class to abstract dealing with sockets and streams away from the Vooga networking API users so they can simply send() and receive() messages from a socket.


Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
protected  java.io.PrintStream outStream
           
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
GameSocket(java.net.Socket sock)
          Save the socket as well as it's input and output streams.
 
Method Summary
 void closeConnections()
          Close the socket.
protected  void finalize()
          Make sure the socket is closed and if not close it.
 boolean isConnected()
          Return if the GameSocket is still connected, meaning it can read and write from and to a socket.
 java.lang.String receive()
          Read the latest message from the socket.
 void run()
           
 void send(java.lang.String s)
          Send a message to the socket.
 
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
 

Field Detail

outStream

protected java.io.PrintStream outStream
Constructor Detail

GameSocket

public GameSocket(java.net.Socket sock)
Save the socket as well as it's input and output streams.

Parameters:
sock - the socket to communicate through.
Method Detail

send

public void send(java.lang.String s)
Send a message to the socket.

Parameters:
s - the message to send

receive

public java.lang.String receive()
                         throws java.io.IOException
Read the latest message from the socket.

Throws:
java.io.IOException

run

public void run()
Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread

isConnected

public boolean isConnected()
Return if the GameSocket is still connected, meaning it can read and write from and to a socket.


closeConnections

public void closeConnections()
Close the socket.


finalize

protected void finalize()
Make sure the socket is closed and if not close it.

Overrides:
finalize in class java.lang.Object