ctf.network.tcp
Class TestConnection

java.lang.Object
  extended by java.lang.Thread
      extended by ctf.network.tcp.Connection
          extended by ctf.network.tcp.TestConnection
All Implemented Interfaces:
java.lang.Runnable

public class TestConnection
extends Connection

A connection that times out after 100 ms (the maximum allowable latency according to the CTF specification). In reality, we allow more delay, since we can't control things like processor and thread scheduling.


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 java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
TestConnection(java.net.Socket socket)
          Construct a new (already-opened) connection
TestConnection(java.lang.String host, int port)
          Construct a new connection to a server
 
Method Summary
 java.lang.String getLine()
          Receive a line (string terminated by newline) from the socket with the newline character removed.
 void sendLine(java.lang.String line)
          Send a newline-terminated line across the socket
 
Methods inherited from class ctf.network.tcp.Connection
close, connectedTo, finalize, run, send, setOwner, toString
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, 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, yield
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TestConnection

public TestConnection(java.lang.String host,
                      int port)
               throws java.io.IOException,
                      UninitializedSocketException,
                      java.net.UnknownHostException
Construct a new connection to a server

Parameters:
host - The IP host to connect to
port - The TCP port to connect to
Throws:
java.io.IOException - for general connection problems
UninitializedSocketException - if socket doesn't initialize
java.net.UnknownHostException - if the host is unknown

TestConnection

public TestConnection(java.net.Socket socket)
               throws java.io.IOException,
                      UninitializedSocketException
Construct a new (already-opened) connection

Parameters:
socket - The socket to connect with
Throws:
java.io.IOException - on error getting an I/O stream from Socket
UninitializedSocketException - if connection not established
Method Detail

sendLine

public void sendLine(java.lang.String line)
              throws java.io.IOException,
                     SocketClosedException,
                     UninitializedSocketException
Description copied from class: Connection
Send a newline-terminated line across the socket

Overrides:
sendLine in class Connection
Throws:
java.io.IOException
SocketClosedException
UninitializedSocketException

getLine

public java.lang.String getLine()
                         throws java.io.IOException,
                                NetworkException
Description copied from class: Connection
Receive a line (string terminated by newline) from the socket with the newline character removed.

Overrides:
getLine in class Connection
Throws:
java.io.IOException
NetworkException