org.openmuc.jositransport
Class TConnection

java.lang.Object
  extended by org.openmuc.jositransport.TConnection

public class TConnection
extends java.lang.Object


Field Summary
 byte[] tSelLocal
           
 byte[] tSelRemote
           
 
Constructor Summary
protected TConnection(java.net.Socket socket, int maxTPDUSizeParam, int messageTimeout, int messageFragmentTimeout)
           
 
Method Summary
 void close()
           
 void disconnect()
          This function sends a Disconnect Request but does not wait for a Disconnect Confirm.
protected  void listenForCR()
          This function is called once a client has connected to the server.
 byte[] receive()
          This function will throw an EOFException in case a Disconnect Request (DR) or ErrorPDU (ER) was received or the socket was simply closed.
 void send(byte[] tsdu, int offset, int length)
           
 void send(java.util.List<byte[]> tsdus, java.util.List<java.lang.Integer> offsets, java.util.List<java.lang.Integer> lengths)
           
 void setMessageFragmentTimeout(int messageFragmentTimeout)
          Set the TConnection timeout for receiving data once the beginning of a message has been received.
 void setMessageTimeout(int messageTimeout)
          Set the TConnection timeout for waiting for the first byte of a new message.
protected  void startConnection()
          Starts a connection, sends a CR, waits for a CC and throws an IOException if not successful
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

tSelRemote

public byte[] tSelRemote

tSelLocal

public byte[] tSelLocal
Constructor Detail

TConnection

protected TConnection(java.net.Socket socket,
                      int maxTPDUSizeParam,
                      int messageTimeout,
                      int messageFragmentTimeout)
               throws java.io.IOException
Throws:
java.io.IOException
Method Detail

listenForCR

protected void listenForCR()
                    throws java.io.IOException
This function is called once a client has connected to the server. It listens for a Connection Request (CR). If this is successful it replies afterwards with a Connection Confirm (CC). According to the norm a syntax error in the CR should be followed by an ER. This implementation does not send an ER because it seems unnecessary.

Throws:
java.io.IOException

startConnection

protected void startConnection()
                        throws java.io.IOException
Starts a connection, sends a CR, waits for a CC and throws an IOException if not successful

Throws:
java.io.IOException

send

public void send(java.util.List<byte[]> tsdus,
                 java.util.List<java.lang.Integer> offsets,
                 java.util.List<java.lang.Integer> lengths)
          throws java.io.IOException
Throws:
java.io.IOException

send

public void send(byte[] tsdu,
                 int offset,
                 int length)
          throws java.io.IOException
Throws:
java.io.IOException

setMessageTimeout

public void setMessageTimeout(int messageTimeout)
                       throws java.net.SocketException
Set the TConnection timeout for waiting for the first byte of a new message. Default is 0 (unlimited)

Parameters:
messageTimeout - in milliseconds
Throws:
java.net.SocketException

setMessageFragmentTimeout

public void setMessageFragmentTimeout(int messageFragmentTimeout)
                               throws java.net.SocketException
Set the TConnection timeout for receiving data once the beginning of a message has been received. Default is 60000 (60 seconds)

Parameters:
messageFragmentTimeout - in milliseconds
Throws:
java.net.SocketException

receive

public byte[] receive()
               throws java.io.IOException
This function will throw an EOFException in case a Disconnect Request (DR) or ErrorPDU (ER) was received or the socket was simply closed. An IOException is thrown in case of a syntax error. A SocketTimeoutException is thrown if a MessageTimeout or MessageFragmentTimeout occurred. For all exceptions except the MessageTimeout the connection is closed by this function.

Throws:
java.io.IOException

disconnect

public void disconnect()
This function sends a Disconnect Request but does not wait for a Disconnect Confirm.


close

public void close()