org.openmuc.jositransport

## Class ServerTSap

- java.lang.Object
- - org.openmuc.jositransport.ServerTSap

    public class ServerTSap
    extends java.lang.Object

This class implements the server Transport Service Access Point (TSAP) over TCP/IP as defined in RFC 1006, ISO 8072, and ISO 8073. It can be used to listen for incoming TConnections.

### Constructor Summary

Constructors
Constructor and Description
`ServerTSap(int port, int backlog, java.net.InetAddress bindAddr, TConnectionListener conListener)` Use this constructor to create a server TSAP that can listen on a port.
`ServerTSap(int port, int backlog, java.net.InetAddress bindAddr, TConnectionListener connectionListener, javax.net.ServerSocketFactory serverSocketFactory)` Use this constructor to create a server TSAP that can listen on a port, with a specified ServerSocketFactory.
`ServerTSap(int port, TConnectionListener conListener)` Use this constructor to create a server TSAP that can listen on a port.

### Method Summary

All Methods Static Methods Instance Methods Concrete Methods
`static int` `getMaxTPDUSize(int maxTPDUSizeParam)` Calculates and returns the maximum TPDUSize.
`int` `getMaxTPDUSizeParam()` Get the maximum TPDU size parameter to be used by this TSAP
`void` `setMaxConnections(int maxConnections)` Set the maximum number of connections that are allowed in parallel by the Server SAP.
`void` `setMaxTPDUSizeParam(int maxTPduSizeParam)` Set the maxTPDUSize.
`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.
`void` `startListening()` Starts a new thread that listens on the configured port.
`void` `stopListening()` Stop listing on the port.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Constructor Detail

#### ServerTSap

    public ServerTSap(int port,
                      TConnectionListener conListener)

Use this constructor to create a server TSAP that can listen on a port.

Parameters:
  `port` - the TCP port that the ServerSocket will connect to. Should be between 1 and 65535.
  `conListener` - the ConnectionListener that will be notified when remote TSAPs are connecting or the server stopped listening.

#### ServerTSap

    public ServerTSap(int port,
                      int backlog,
                      java.net.InetAddress bindAddr,
                      TConnectionListener conListener)

Use this constructor to create a server TSAP that can listen on a port.

Parameters:
  `port` - the TCP port that the ServerSocket will connect to. Should be between 1 and 65535.
  `conListener` - the ConnectionListener that will be notified when remote TSAPs are connecting or the server stopped listening.
  `backlog` - is passed to the java.net.ServerSocket
  `bindAddr` - the IP address to bind to. It is passed to java.net.ServerSocket

#### ServerTSap

    public ServerTSap(int port,
                      int backlog,
                      java.net.InetAddress bindAddr,
                      TConnectionListener connectionListener,
                      javax.net.ServerSocketFactory serverSocketFactory)

Use this constructor to create a server TSAP that can listen on a port, with a specified ServerSocketFactory.

Parameters:
  `port` - the TCP port that the ServerSocket will connect to. Should be between 1 and 65535.
  `connectionListener` - the ConnectionListener that will be notified when remote TSAPs are connecting or the server stopped listening.
  `backlog` - is passed to the java.net.ServerSocket
  `bindAddr` - the IP address to bind to. It is passed to java.net.ServerSocket
  `serverSocketFactory` - The ServerSocketFactory to be used to create the ServerSocket

### Method Detail

#### startListening

    public void startListening()
                        throws java.io.IOException

Starts a new thread that listens on the configured port. This method is non-blocking.

Throws:
  `java.io.IOException` - if a starting to listen fails

#### stopListening

    public void stopListening()

Stop listing on the port. Stops the server thread.

#### setMaxTPDUSizeParam

    public void setMaxTPDUSizeParam(int maxTPduSizeParam)

Set the maxTPDUSize. The default maxTPduSize is 65531 (see RFC 1006).

Parameters:
  `maxTPduSizeParam` - The maximum length is equal to 2^(maxTPduSizeParam) octets. Note that the actual TSDU size that can be transfered is equal to TPduSize-3. Default is 65531 octets (see RFC 1006), 7 <= maxTPduSizeParam <= 16, needs to be set before listening or connecting

#### setMaxConnections

    public void setMaxConnections(int maxConnections)

Set the maximum number of connections that are allowed in parallel by the Server SAP.

Parameters:
  `maxConnections` - the number of connections allowed (default is 100)

#### setMessageTimeout

    public void setMessageTimeout(int messageTimeout)

Set the TConnection timeout for waiting for the first byte of a new message. Default is 0 (unlimited)

Parameters:
  `messageTimeout` - in milliseconds

#### setMessageFragmentTimeout

    public void setMessageFragmentTimeout(int messageFragmentTimeout)

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

#### getMaxTPDUSizeParam

    public int getMaxTPDUSizeParam()

Get the maximum TPDU size parameter to be used by this TSAP

Returns:
  the maximum TPDU size parameter

#### getMaxTPDUSize

    public static int getMaxTPDUSize(int maxTPDUSizeParam)

Calculates and returns the maximum TPDUSize. This is equal to 2^(maxTPDUSizeParam)

Parameters:
  `maxTPDUSizeParam` - the size parameter
Returns:
  the maximum TPDU size