protocol
Class Connection

java.lang.Object
  |
  +--protocol.Connection

public class Connection
extends Object

Class to manage the connection between a player and the ICFP-2002 programming server.

Version:
$Revision: 1.3 $
Author:
Allen D. Ball

Constructor Summary
Connection(Socket socket)
          Creates a connection between a player and the game server (on the argument socket).
Connection(Socket socket, PrintStream tracePrintStream)
          Creates a connection between a player and the game server (on the argument socket).
 
Method Summary
 BufferedReader getReader()
          Method to get a reader for the connection socket.
 Socket getSocket()
          Method to get the Socket used for communicating to the game server on this connection.
protected  PrintWriter getWriter()
          Method to get a writer for the connection socket.
 String read()
          Read a line of text from the game server discarding line terminator(s).
 void send(Object object)
          Sends the argument object (by invoking its Object.toString() method) to the server with the proper line terminator(s).
 void send(String string)
          Sends the argument string to the server with the proper line terminator(s).
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Connection

public Connection(Socket socket,
                  PrintStream tracePrintStream)
Creates a connection between a player and the game server (on the argument socket).
Parameters:
socket - The socket connecting the player to the game server.
trace - True if communications with the server should be traced

Connection

public Connection(Socket socket)
Creates a connection between a player and the game server (on the argument socket).
Parameters:
socket - The socket connecting the player to the game server.
Method Detail

getSocket

public Socket getSocket()
Method to get the Socket used for communicating to the game server on this connection.
Returns:
The socket for this connection.

getReader

public BufferedReader getReader()
                         throws IOException
Method to get a reader for the connection socket.
Returns:
A reader for the socket.
Throws:
IOException - Thrown if an exception is encountered communicating on the connection.

read

public String read()
            throws IOException
Read a line of text from the game server discarding line terminator(s).
Returns:
A String containing the contents of the line, not including any line-termination characters.
Throws:
IOException - Thrown if an exception is encountered communicating on the connection.

getWriter

protected PrintWriter getWriter()
                         throws IOException
Method to get a writer for the connection socket.
Returns:
A print-writer for the socket.
Throws:
IOException - Thrown if an exception is encountered communicating on the connection.

send

public void send(String string)
          throws IOException
Sends the argument string to the server with the proper line terminator(s).
Parameters:
string - The string to be sent to the game server.
Throws:
IOException - Thrown if an exception is encountered communicating on the connection.

send

public void send(Object object)
          throws IOException
Sends the argument object (by invoking its Object.toString() method) to the server with the proper line terminator(s).
Parameters:
object - The object to be sent to the game server.
Throws:
IOException - Thrown if an exception is encountered communicating on the connection.


Copyright 2002 Allen D. Ball. All rights reserved.