Package org.openmuc.j60870
Class ClientConnectionBuilder
- java.lang.Object
-
- org.openmuc.j60870.ClientConnectionBuilder
-
public class ClientConnectionBuilder extends java.lang.Object
The client connection builder is used to connect to IEC 60870-5-104 servers. A client application that wants to connect to a server should first create an instance ofClientConnectionBuilder
. Next all the necessary configuration parameters can be set. Finally thebuild()
function is called to connect to the server. An instance ofClientConnectionBuilder
can be used to create an unlimited number of connections. Changing the parameters of aClientConnectionBuilder
has no affect on connections that have already been created.Note that the configured lengths of the fields COT, CA and IOA have to be the same for all communicating nodes in a network. The default values used by
ClientConnectionBuilder
are those most commonly used in IEC 60870-5-104 communication.
-
-
Constructor Summary
Constructors Constructor Description ClientConnectionBuilder(java.lang.String inetAddress)
ClientConnectionBuilder(java.net.InetAddress address)
Creates a client connection builder that can be used to connect to the given address.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Connection
build()
Connects to the server.ClientConnectionBuilder
setAddress(java.net.InetAddress address)
Sets the address to connect to.T
setAllowedASduTypes(java.util.List<ASduType> allowedTypes)
T
setCommonAddressFieldLength(int length)
Sets the length of the Common Address (CA) field of the ASDU.
Allowed values are 1 or 2.
Default is 2.ClientConnectionBuilder
setConnectionEventListener(ConnectionEventListener listener)
ClientConnectionBuilder
setConnectionTimeout(int time_t0)
Sets connection time out t0, in milliseconds.
t0 (connectionTimeout) must be between 1000ms and 255000ms.T
setCotFieldLength(int length)
Sets the length of the Cause Of Transmission (COT) field of the ASDU.
Allowed values are 1 or 2.
Default is 2.T
setIoaFieldLength(int length)
Sets the length of the Information Object Address (IOA) field of the ASDU.
Allowed values are 1, 2 or 3.
Default is 3.ClientConnectionBuilder
setLocalAddress(java.net.InetAddress address, int port)
Sets the local (client) address and port the socket will connect to.T
setMaxIdleTime(int time_t3)
Sets the maximum time in ms that the connection may be idle before sending a test frame.T
setMaxNumOfOutstandingIPdus(int maxNum)
Sets the number of maximum difference send sequence number to send acknowledge variable before Connection.send will block.T
setMaxTimeNoAckReceived(int time_t1)
Sets the maximum time in ms that no acknowledgement has been received (for I-Frames or Test-Frames) before actively closing the connection.T
setMaxTimeNoAckSent(int time_t2)
Sets the maximum time in ms before confirming received messages that have not yet been acknowledged using an S format APDU.T
setMaxUnconfirmedIPdusReceived(int maxNum)
Sets the number of unacknowledged I format APDUs received before the connection will automatically send an S format APDU to confirm them.T
setMessageFragmentTimeout(int time)
Sets SO_TIMEOUT with the specified timeout, in milliseconds.ClientConnectionBuilder
setPort(int port)
Sets the port to connect to.ClientConnectionBuilder
setReservedASduTypeDecoder(ReservedASduTypeDecoder reservedASduTypeDecoder)
Sets an implementation of the ReservedASduTypeDecoder to define supported reserved ASdusClientConnectionBuilder
setSocketFactory(javax.net.SocketFactory socketFactory)
Set the socket factory to used to create the socket for the connection.T
useSharedThreadPool()
-
-
-
Constructor Detail
-
ClientConnectionBuilder
public ClientConnectionBuilder(java.net.InetAddress address)
Creates a client connection builder that can be used to connect to the given address.- Parameters:
address
- the address to connect to
-
ClientConnectionBuilder
public ClientConnectionBuilder(java.lang.String inetAddress) throws java.net.UnknownHostException
- Throws:
java.net.UnknownHostException
-
-
Method Detail
-
setSocketFactory
public ClientConnectionBuilder setSocketFactory(javax.net.SocketFactory socketFactory)
Set the socket factory to used to create the socket for the connection. The default isSocketFactory.getDefault()
. You could pass anSSLSocketFactory
to enable SSL.- Parameters:
socketFactory
- the socket factory- Returns:
- this builder
-
setReservedASduTypeDecoder
public ClientConnectionBuilder setReservedASduTypeDecoder(ReservedASduTypeDecoder reservedASduTypeDecoder)
Sets an implementation of the ReservedASduTypeDecoder to define supported reserved ASdus- Parameters:
reservedASduTypeDecoder
- implementation of the ReservedASduTypeDecoder
-
setPort
public ClientConnectionBuilder setPort(int port)
Sets the port to connect to. The default port is 2404.- Parameters:
port
- the port to connect to.- Returns:
- this builder
-
setAddress
public ClientConnectionBuilder setAddress(java.net.InetAddress address)
Sets the address to connect to.- Parameters:
address
- the address to connect to.- Returns:
- this builder
-
setLocalAddress
public ClientConnectionBuilder setLocalAddress(java.net.InetAddress address, int port)
Sets the local (client) address and port the socket will connect to.- Parameters:
address
- the local address the socket is bound to, or null for any local address.port
- the local port the socket is bound to or zero for a system selected free port.- Returns:
- this builder
-
setConnectionTimeout
public ClientConnectionBuilder setConnectionTimeout(int time_t0)
Sets connection time out t0, in milliseconds.
t0 (connectionTimeout) must be between 1000ms and 255000ms.- Parameters:
time_t0
- the timeout in milliseconds. Default is 20 s- Returns:
- this builder
-
setConnectionEventListener
public ClientConnectionBuilder setConnectionEventListener(ConnectionEventListener listener)
-
build
public Connection build() throws java.io.IOException
Connects to the server. The TCP/IP connection is build up and aConnection
object is returned that can be used to communicate with the server.- Returns:
- the
Connection
object that can be used to communicate with the server. - Throws:
java.io.IOException
- if any kind of error occurs during connection build up.
-
setCotFieldLength
public T setCotFieldLength(int length)
Sets the length of the Cause Of Transmission (COT) field of the ASDU.
Allowed values are 1 or 2.
Default is 2.- Parameters:
length
- the length of the Cause Of Transmission field- Returns:
- this builder
-
setCommonAddressFieldLength
public T setCommonAddressFieldLength(int length)
Sets the length of the Common Address (CA) field of the ASDU.
Allowed values are 1 or 2.
Default is 2.- Parameters:
length
- the length of the Common Address (CA) field- Returns:
- this builder
-
setIoaFieldLength
public T setIoaFieldLength(int length)
Sets the length of the Information Object Address (IOA) field of the ASDU.
Allowed values are 1, 2 or 3.
Default is 3.- Parameters:
length
- the length of the Information Object Address field- Returns:
- this builder
-
setMaxTimeNoAckReceived
public T setMaxTimeNoAckReceived(int time_t1)
Sets the maximum time in ms that no acknowledgement has been received (for I-Frames or Test-Frames) before actively closing the connection. This timeout is called t1 by the standard.
Default is 15s, minimum is 1s, maximum is 255s.
t1 (maxTimeNoAckReceived) has to be greater then t2 (maxTimeNoAckSent) and t1 has to be smaller then t3 (maxIdleTime) (t1 > t2 and t1 < t3)- Parameters:
time_t1
- the maximum time in ms that no acknowledgement has been received before actively closing the connection.- Returns:
- this builder
-
setMaxTimeNoAckSent
public T setMaxTimeNoAckSent(int time_t2)
Sets the maximum time in ms before confirming received messages that have not yet been acknowledged using an S format APDU. This timeout is called t2 by the standard.
Default is 10s, minimum is 1s, maximum is 255s.
t2 (maxTimeNoAckSent) has to be smaller then t1 (maxTimeNoAckReceived), t3 > t1.- Parameters:
time_t2
- the maximum time in ms before confirming received messages that have not yet been acknowledged using an S format APDU.- Returns:
- this builder
-
setMaxIdleTime
public T setMaxIdleTime(int time_t3)
Sets the maximum time in ms that the connection may be idle before sending a test frame. This timeout is called t3 by the standard.
Default is 20s, minimum is 1s, maximum is 172800s (48h).
t3 (maxIdleTime) has to be bigger then t1 (maxTimeNoAckReceived), t3 > t1.- Parameters:
time_t3
- the maximum time in ms that the connection may be idle before sending a test frame.- Returns:
- this builder
-
setMaxNumOfOutstandingIPdus
public T setMaxNumOfOutstandingIPdus(int maxNum)
Sets the number of maximum difference send sequence number to send acknowledge variable before Connection.send will block. This parameter is called k by the standard.
Default is 12, minimum is 1, maximum is 32767.- Parameters:
maxNum
- the maximum number of sequentially numbered I format APDUs that the DTE may have outstanding- Returns:
- this builder
-
setMaxUnconfirmedIPdusReceived
public T setMaxUnconfirmedIPdusReceived(int maxNum)
Sets the number of unacknowledged I format APDUs received before the connection will automatically send an S format APDU to confirm them. This parameter is called w by the standard. Default is 8, minimum is 1, maximum is 32767.- Parameters:
maxNum
- the number of unacknowledged I format APDUs received before the connection will automatically send an S format APDU to confirm them.- Returns:
- this builder
-
setMessageFragmentTimeout
public T setMessageFragmentTimeout(int time)
Sets SO_TIMEOUT with the specified timeout, in milliseconds.- Parameters:
time
- the timeout in milliseconds. Default is 5 s, minimum 100 ms.- Returns:
- this builder
-
useSharedThreadPool
public T useSharedThreadPool()
-
setAllowedASduTypes
public T setAllowedASduTypes(java.util.List<ASduType> allowedTypes)
-
-