org.opcfoundation.ua.transport.tcp.io
Class TcpConnection

java.lang.Object
  extended by org.opcfoundation.ua.transport.tcp.io.TcpConnection
All Implemented Interfaces:
IConnection

public class TcpConnection
extends Object
implements IConnection

This class implements OPC UA Secure Conversation (UASC) for client to server communication.

OPC UA TCP is a simple TCP based protocol that establishes a full duplex channel between a client and server. This protocol has two key features that differentiate it from HTTP. First, this protocol allows responses to be returned in any order. Second, this protocol allows responses to be returned on a different socket if communication failures causes temporary socket interruption. The OPC UA TCP protocol is designed to work with the SecureChannel implemented by a layer higher in the stack. For this reason, the OPC UA TCP protocol defines its interactions with the SecureChannel in addition to the wire protocol.

Features included in this class: o Establishing connection, Handshake o Sync and Async encryption Features excluded in this class: o Reconnect (See SecureChannel) o Token Renewal (See SecureChannel) TcpConnection is instantiated and managed by SecureChannel which also handles Reconnection and token renewal.

OpenSecureChannelRequest and OpenSecureChannelResponse is ciphered with asymmetric encryption using the certificates set in initialize. Asymmetric encryption is omited if server certificate is null. (This is not allowed in Part 4, but is in Part 6). DiscoveryClient uses unencrypted connection. TcpConnection captures security tokens from OpenSecureChannel conversation and uses them for symmetric messaging. The oldest non-expired token is used.

Author:
Toni Kalajainen (toni.kalajainen@vtt.fi)

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.opcfoundation.ua.transport.tcp.io.IConnection
IConnection.IMessageListener
 
Constructor Summary
TcpConnection()
           
 
Method Summary
 void addConnectionListener(IConnectionListener listener)
          Add response listener
 void addMessageListener(IConnection.IMessageListener listener)
          Add input stream message listener.
 void close()
          Close the socket connection.
 void dispose()
          Optional dispose closes connection and clears all variables
 EndpointConfiguration getEndpointConfiguration()
          Getter for the field endpointConfiguration.
 EndpointDescription getEndpointDescription()
          Getter for the field endpointDescription.
 int getHandshakeTimeout()
          Getter for the field handshakeTimeout.
 EncoderContext getMessageContext()
          getMessageContext.
 int getProtocolVersion()
          Get the protocol version agreen in the hand-shake
static int getReceiveBufferSize()
          Getter for the field receiveBufferSize.
static int getSendBufferSize()
          Getter for the field sendBufferSize.
protected  Socket getSocket()
          Getter for the field socket.
 SocketAddress getSocketAddress()
          Get the initialized socket address
 void initialize(InetSocketAddress addr, TransportChannelSettings settings, EncoderContext ctx)
          Set connection configuration parameters.
 void initialize(String url, TransportChannelSettings settings, EncoderContext ctx)
          
 void initialize(TransportChannelSettings settings, EncoderContext ctx)
          initialize.
 void open()
          open.
 void reconnect()
          reconnect.
 void removeConnectionListener(IConnectionListener listener)
          Add response listener
 void removeMessageListener(IConnection.IMessageListener listener)
          removeMessageListener.
 void sendRequest(ServiceRequest request, int secureChannelId, int requestId)
          Send request to the connection.
 void setHandshakeTimeout(int handshakeTimeout)
          Setter for the field handshakeTimeout.
static void setReceiveBufferSize(int receiveBufferSize)
          Define the receiveBufferSize to use for the connection socket.
static void setSendBufferSize(int sendBufferSize)
          Define the sendBufferSize to use for the connection socket.
protected  void setSocket(Socket socket)
          Setter for the field socket.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TcpConnection

public TcpConnection()
Method Detail

setSocket

protected void setSocket(Socket socket)

Setter for the field socket.

Parameters:
socket - the socket to set

getReceiveBufferSize

public static int getReceiveBufferSize()

Getter for the field receiveBufferSize.

Returns:
the receiveBufferSize to use for the connection socket.

setReceiveBufferSize

public static void setReceiveBufferSize(int receiveBufferSize)
Define the receiveBufferSize to use for the connection socket. You must define the value before the client is connected. The value is applied to the underlying socket, right the socket is created.

Default value: 0, which omits the parameter and the default value for the socket (depending on the operating system) is used.

Parameters:
receiveBufferSize - the new size in bytes
See Also:
"http://fasterdata.es.net/host-tuning/background/"

getSendBufferSize

public static int getSendBufferSize()

Getter for the field sendBufferSize.

Returns:
the sendBufferSize to use for the connection socket.

setSendBufferSize

public static void setSendBufferSize(int sendBufferSize)
Define the sendBufferSize to use for the connection socket. You must define the value before the client is connected. The value is applied to the underlying socket, right the socket is created.

Default value: 0, which omits the parameter and the default value for the socket (depending on the operating system) is used.

Parameters:
sendBufferSize - the new size in bytes

initialize

public void initialize(TransportChannelSettings settings,
                       EncoderContext ctx)
                throws ServiceResultException

initialize.

Parameters:
settings - a TransportChannelSettings object.
ctx - a EncoderContext object.
Throws:
ServiceResultException - if any.

initialize

public void initialize(String url,
                       TransportChannelSettings settings,
                       EncoderContext ctx)
                throws ServiceResultException

Throws:
ServiceResultException

initialize

public void initialize(InetSocketAddress addr,
                       TransportChannelSettings settings,
                       EncoderContext ctx)
                throws ServiceResultException
Set connection configuration parameters.

Specified by:
initialize in interface IConnection
Parameters:
addr - a InetSocketAddress object.
settings - a TransportChannelSettings object.
ctx - a EncoderContext object.
Throws:
ServiceResultException - if any.

open

public void open()
          throws ServiceResultException

open.

Specified by:
open in interface IConnection
Throws:
ServiceResultException - if any.

close

public void close()
Close the socket connection. This method does not request CloseSecureChannel. Does nothing if it is already closed or was never opened. This method is invoked by the user and internally by read thread.

Specified by:
close in interface IConnection

getSocket

protected Socket getSocket()

Getter for the field socket.

Returns:
a Socket object.

reconnect

public void reconnect()
               throws ServiceResultException

reconnect.

Specified by:
reconnect in interface IConnection
Throws:
ServiceResultException - if any.

getEndpointConfiguration

public EndpointConfiguration getEndpointConfiguration()

Getter for the field endpointConfiguration.

Returns:
a EndpointConfiguration object.

getEndpointDescription

public EndpointDescription getEndpointDescription()

Getter for the field endpointDescription.

Returns:
a EndpointDescription object.

getMessageContext

public EncoderContext getMessageContext()

getMessageContext.

Returns:
a EncoderContext object.

dispose

public void dispose()
Optional dispose closes connection and clears all variables

Specified by:
dispose in interface IConnection

sendRequest

public void sendRequest(ServiceRequest request,
                        int secureChannelId,
                        int requestId)
                 throws ServiceResultException
Send request to the connection. If the connection is closed Bad_NotConnected is thrown Send service request using a given secure channel and operation time out. The operation may be interrupted by interrupting the calling thread with Thread.interrupt().

Specified by:
sendRequest in interface IConnection
secureChannelId - a int.
Throws:
ServiceResultException - varies. Bad_NotConnected if connection is not established

getHandshakeTimeout

public int getHandshakeTimeout()

Getter for the field handshakeTimeout.

Returns:
a int.

setHandshakeTimeout

public void setHandshakeTimeout(int handshakeTimeout)

Setter for the field handshakeTimeout.

Parameters:
handshakeTimeout - a int.

addMessageListener

public void addMessageListener(IConnection.IMessageListener listener)
Add input stream message listener. All incoming messages are notified to the listener. The listener may not block in message handling as the message is handled in read thread.

Specified by:
addMessageListener in interface IConnection
Parameters:
listener - message listener

removeMessageListener

public void removeMessageListener(IConnection.IMessageListener listener)

removeMessageListener.

Specified by:
removeMessageListener in interface IConnection
Parameters:
listener - a IMessageListener object.

addConnectionListener

public void addConnectionListener(IConnectionListener listener)
Add response listener

Specified by:
addConnectionListener in interface IConnection
Parameters:
listener - a IConnectionListener object.

removeConnectionListener

public void removeConnectionListener(IConnectionListener listener)
Add response listener

Specified by:
removeConnectionListener in interface IConnection
Parameters:
listener - a IConnectionListener object.

getProtocolVersion

public int getProtocolVersion()
Get the protocol version agreen in the hand-shake

Returns:
connection protocol version

getSocketAddress

public SocketAddress getSocketAddress()
Get the initialized socket address

Returns:
socket address or null if the connection has not been initialized


Copyright © 2018. All rights reserved.