gizmoball.worldmodels
Class SynchronizedSocket

java.lang.Object
  extended by gizmoball.worldmodels.SynchronizedSocket

public class SynchronizedSocket
extends java.lang.Object

A socket that abstracts away some of the threading and synchronization.


Method Summary
static SynchronizedSocket createClientSocket(java.lang.String hostname, int portNum)
          Creates a socket by trying to connect to a server on a specified port number.
static SynchronizedSocket createServerSocket(int portNum)
          Listens for connections on the specified port, then returns a SynchronizedSocket from any connection that results.
 void println(java.lang.String s)
          Posts the string to the socket.
 java.lang.String readLine()
          reads the next line of input from the socket.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

readLine

public java.lang.String readLine()
reads the next line of input from the socket. if there is nothing to read, returns null


println

public void println(java.lang.String s)
Posts the string to the socket.


createServerSocket

public static SynchronizedSocket createServerSocket(int portNum)
                                             throws java.io.IOException
Listens for connections on the specified port, then returns a SynchronizedSocket from any connection that results.

Parameters:
portNum - the port to listen on
Returns:
a socket created from listening on that port
Throws:
java.io.IOException - if anything goes wrong

createClientSocket

public static SynchronizedSocket createClientSocket(java.lang.String hostname,
                                                    int portNum)
                                             throws java.io.IOException
Creates a socket by trying to connect to a server on a specified port number.

Parameters:
hostname - the host (hostname or IP address) to connect to
portNum - the port number to connect to
Returns:
the socket connecting to that host
Throws:
java.io.IOException - if anything goes wrong