Contents

Socket Adapter can be used in sending data to sockets and receiving data from sockets. This adapter will have two modes of operation.

  • Server
    Acts as a server if 'Create Socket?' property is set to true. In server mode adapter will create a socket on the configured port provided in the component property sheet and listens for connections. Once a connection is created, messages coming on the input port will be sent to the connected client/clients and the messages received from the client will be sent to output port.
  • Client
    Acts as a client if 'Create Socket ?' property is set to false. In client mode adapter will connect to the socket configured. If a successful connection is made then the message coming on the input port will be sent to the server and the received messages will be sent to the output port.

Configuration

Configuration attributes in the SocketAdapter Configuration Property Sheet (CPS) with Expert Properties enabled is explained below.


Figure 1: SocketAdapter Configuration CPS

Attributes

  • Create Socket ?:
    • Enable - Acts as a server by creating a socket on the specified port and listens for client connections.
    • Disable - Acts as client assuming that that server is already running on the specified port and connects to it.
  • Server IP: IP address of the socket
  • Port: Port of the socket
  • Message Type: Mode of the message transfer.
    • Text Message: Messages will be encoded and decoded as Strings.
    • Byte Message: Messages will be encoded and decoded as bytes.
  • Decoding Type: Messages received in the communication will be decoded in the following two ways.
    • Delimiter Based: Messages are decoded based on the delimiter configured.
    • Length Based: Messages are decode based on the length of the message.
    • None: All messages present in the stream are fetched.
  • Delimiter: Delimiter to be used as an end of message.

    Icon

    Hexadecimal Delimiters can also be used. For hexadecimal delimiter, it should start with "0x" . For example, if you want to use "1F" as hexadecimal delimiter, then provide delimiter as "0x1F"

  • Append Delimiter while sending message: If yes, delimiter provided in the configuration will be appended to the input message before sending it to the socket.

    Icon

    In a simple Client-Server Socket scenerio, "Append Delimiter while sending message" property should be true. As message received at the input port of Server does not contain delimiter (message is processed based on client configuration, based on delimiter). So, this property appends the delimiter to message on input port of Server.

  • Include Delimiter in the received message: This property is visible only when Decoding type is Delimiter Based. Upon decoding the received data from socket, message will be sent to the output port with the delimiter included in it.
  • Maximum Message Length (bytes): Length of the largest message in the messages that are expected to receive. This property is visible only when Decoding type is Delimiter Based. While decoding messages based on delimiter if a delimiter is not received till this length then a BufferDataException will occur.

    Icon
    • Instead of waiting forever to match a delimiter, this property helps if the stream receiving is invalid or corrupted.
    • Specify a larger value if the length of the receiving messages is unknown.
  • Message Length (bytes)
    This property specifies the length of the message in case of Length Based decoding. This property is visible only when the property Decoding Type is set to Length Based.
    This property is given by number of bytes.In case of 'message type' as Text, for UTF-8 charset:1 char is 1 byte;for UTF-16 charset: 1 char is 2 bytes.
  • Write Timeout for Session (milli seconds): A Session write time out will happen if a write operation (while sending message to socket) takes more time than this value.
  • Is Synchronous?: Synchronous communication is done between client and server. Messages from client are send to server till client receives response and if no response received from server till given suspend timeout, next message HYPERLINK "slot: This property is visible only when Create Socket ? property is false i.e. for Client."sent. This property is visible only when Create Socket ? property is false i.e. for Client.
  • Suspend Timeout (milli seconds): If the message send by client takes more time than suspend timeout to execute, then the next message is sent.
  • SynchronousCommunication

    Icon

     "Is synchronous?" option is enabled for Client only.


    Figure 2: CPS with Synchronous mode enabled

  • Enable SSL?: By enabling SSL and providing the required key store/trust store with respective passwords, secure message transfer can be achieved.
  • Is SSH Enabled?: Specifies if SSH needs to be enabled. If Enabled,The communication will take place through a secure channel only if the server authenticates itself to client through Key Pair and client authenticates to the server using a login name and password
  • SSHUserName:User Name for the SSH Session,used by the client to authenticate itself to the server
  • SSHPassword:Password for the SSH Session,used by the client to authenticate itself to the server
  • IsKeyPairNeeded:Property present at client side only. If set to true,Specifies that the client needs to communicate with the server authenticated by the specified Key Pair .If set to false,client will accept any server key pairs
  • Key Pair Path: Key pair should be provided at run time by the user at both client side and server side for proper authentication A key pair in .pem format is required by the ssh library to perform the key exchange and verification.

    Icon



    Figure 3: CPS with SSH and Key Pair properties enabled

Functional Demonstration

The following Sample flow has two socket adapter, one acting as the server and the other as client. After receiving requests from the client, server will send it to the SMTP component connected to its output port and the response from the SMTP component is sent back to the client.


Figure 4: Sample Event Process

Scenario 1

'Decode Type' as Delimiter

'SampleServer' Component Configuration is shown in the following figure.


Figure 4: Socket Adapter Configuration in Server mode

'SampleClient' Component Configuration is shown in the following figure.


Figure 5: Socket Adapter Configuration in Client mode

Scenario 2

'Decode Type' as Length

'SampleServer' Component Configuration is shown in the following figure.


Figure 6: Socket Adapter Configuration in Server mode

'SampleClient' Component Configuration is shown in the following figure.


Figure 7: Socket Adapter Configuration in Client mode

Scenario 3

'Decode Type as None'

In this case, whatever message is sent to 'SampleServer', will be received by the 'SampleClient'.

Synchronous Use Case

The following Sample flow has one socket adapter,acting as client. After receiving requests from the client, the configured WSSStub(as Server) sends the response back to client.In client configuration, 'SuspendTimeout' is 10 sec. If client fails to receive response within configured suspendtimeout(i.e. 10 sec),then next request message sent by client will be processed and a timeout error message is sent to errorport of client


Figure 8: Sample Event Process


Figure 9: Socket Adapter Configuration in Client mode for Synchronous Communication


Figure 10: Sample Request


Figure 11: Sample Response

Icon

'Is Synhronous?' option can be used with any 'Decode Type' (Delimiter or Length or None).

Useful Tips

  • In 'Delimiter Based' decoding, instead of waiting forever to match a delimiter, 'Maximum Message Length' property helps if the stream being received is invalid or corrupted.
  • Specify a larger value if the length of the receiving messages is unknown.
Icon

To understand the service better, refer the Socket Read/Write example which demonstrates SocketAdapter service features.

Adaptavist ThemeBuilder EngineAtlassian Confluence