Class Connection

java.lang.Object
  extended by Connection

public class Connection
extends java.lang.Object

The Connection class manages a connection with a Soldat server


Constructor Summary
Connection(ConnectionListener listener)
          Creates a new Connection object tied to the specified ConnectionListener
 
Method Summary
 void connect(java.lang.String address, int port)
          Connects to the server with the specified address, on the specified port
 void disconnect()
          Closes any open connection to a Soldat server
 boolean isClosed()
          Tests whether or not the connection socket is closed
 boolean isConnected()
          Tests whether or not the connection socket is connected
 int read()
          Reads a single character from an open connection.
 java.lang.String readString()
          Reads characters up to and including a newline character from the connection socket
 void sendData(java.lang.String data)
          Sends data to the connected Soldat server
 void skip(int num)
          Skips the specified number of bytes of data waiting on the connection socket
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Connection

public Connection(ConnectionListener listener)
Creates a new Connection object tied to the specified ConnectionListener

Parameters:
listener - the object to receive events generated by the connection
Method Detail

connect

public void connect(java.lang.String address,
                    int port)
             throws java.net.UnknownHostException,
                    java.io.IOException
Connects to the server with the specified address, on the specified port

Parameters:
address - the address of the Soldat server, in dotted IP format (X.X.X.X)
port - the port number to connect to (23073 by default)
Throws:
java.net.UnknownHostException
java.io.IOException

disconnect

public void disconnect()
Closes any open connection to a Soldat server


sendData

public void sendData(java.lang.String data)
Sends data to the connected Soldat server

Parameters:
data - the data to send

isClosed

public boolean isClosed()
Tests whether or not the connection socket is closed

Returns:
true if the connection is closed, or false otherwise

isConnected

public boolean isConnected()
Tests whether or not the connection socket is connected

Returns:
true if the socket is connected, or false otherwise

read

public int read()
         throws java.io.IOException
Reads a single character from an open connection. This method blocks until completed

Returns:
the character read from the connection socket
Throws:
java.io.IOException - if an input or output error occurred

readString

public java.lang.String readString()
                            throws java.io.IOException
Reads characters up to and including a newline character from the connection socket

Returns:
a String object containing the received string
Throws:
java.io.IOException - if an input or output error occurred

skip

public void skip(int num)
          throws java.io.IOException
Skips the specified number of bytes of data waiting on the connection socket

Parameters:
num - the number of bytes to skip
Throws:
java.io.IOException