IBM Support

Implementing TCP Socket communication using Sterling B2B Integrator

Technical Blog Post


Abstract

Implementing TCP Socket communication using Sterling B2B Integrator

Body

 

Author: Manisha Khond, IBM Cognitive Engagement, Watson Supply Chain.

How to implement TCP Socket communication using Sterling B2B Integrator?

Sterling Integrator offers following Services and Adapter for Transmission Control Protocol Socket communication.

  • Socket Client Adapter
  • Socket Server Adapter
  • Socket Connect Service
  • Socket Read Service
  • Socket Write Service

 

How to implement outbound Socket Connection from Sterling B2B Integrator to remote Socket Server and send or receive data?

 

  • Configure Socket Client Adapter

image

 

  • Then write a business process to establish the connection with the remote Socket Server using Socket Connect Service and then send the data to the Socket Server using Socket Write Service.

Below sample Business Process establishes connection to the remote Socket Server using Socket Connect Service. Note that you have to reference Socket Client Adapter within Socket Connect Service.Send the data to the Socket Server using Socket Write Service.In this scenario, Socket Server responds with the data after receiving a data file from Sterling B2B Integrator.The data sent by the Socket Server is then read via Socket Read Service. DataNode parameter mentions name of the node under process data where the data that is read from the Socket Read service.The connection is closed by the Socket Close Service.

<process name = "mk_socket">

<rule name="Session Open">

<condition>boolean(/ProcessData/SessionToken)</condition>

</rule>

 

<sequence name="Main">

<operation name="SocketConnectServiceType">

<participant name="SocketConnectService"/>

<output message="SocketConnectServiceTypeInputMessage">

<assign to="." from="*"></assign>

<assign to="RemoteHost">xxx.xx.x.xx</assign>

<assign to="RemotePort">5100</assign>

<assign to="ResponseTimeout">30</assign>

<assign to="SocketClientAdapter">SocketClientAdapter</assign>

</output>

<input message="inmsg">

<assign to="." from="*"></assign>

</input>

</operation>

 

<operation name="SocketWriteServiceType">

<participant name="SocketWriteService"/>

<output message="SocketWriteServiceTypeInputMessage">

<assign to="." from="*"></assign>

<assign to="ResponseTimeout">30</assign>

<assign to="SessionToken" from="/ProcessData/SessionToken/text()"></assign>

</output>

<input message="inmsg">

<assign to="." from="*"></assign>

</input>

</operation>

 

<operation name="SocketReadServiceType">

<participant name="SocketReadService"/>

<output message="SocketReadServiceTypeInputMessage">

<assign to="." from="*"></assign>

<assign to="DataNode">SocketDataRead</assign>

<assign to="EndOfData">35</assign>

<assign to="ResponseTimeout">30</assign>

<assign to="SessionToken" from="/ProcessData/SessionToken/text()"></assign>

</output>

<input message="inmsg">

<assign to="." from="*"></assign>

</input>

</operation>

 

<operation name="SocketCloseServiceType">

<participant name="SocketCloseService"/>

<output message="SocketCloseServiceTypeInputMessage">

<assign to="." from="*"></assign>

<assign to="SessionToken" from="/ProcessData/SessionToken/text()"></assign>

</output>

<input message="inmsg">

<assign to="." from="*"></assign>

</input>

</operation>

 

<onFault>

<sequence name="Error">

<choice name="Choice Start">

<select>

<case ref="Session Open" activity="Session Open"/>

</select>

 

<sequence name="Session Open">

<operation name="SocketCloseServiceType">

<participant name="SocketCloseService"/>

<output message="SocketCloseServiceTypeInputMessage">

<assign to="." from="*"></assign>

<assign to="SessionToken" from="/ProcessData/SessionToken/text()"></assign>

</output>

<input message="inmsg">

<assign to="." from="*"></assign>

</input>

</operation>

</sequence>

</choice>

<operation name="Invoke Business Process Service">

<participant name="InvokeBusinessProcessService"/>

<output message="InvokeBusinessProcessServiceTypeInputMessage">

<assign to="." from="*"></assign>

<assign to="INVOKE_MODE">ASYNC</assign>

<assign to="WFD_NAME">mk_GenericErrorHandler</assign>

</output>

<input message="inmsg">

<assign to="." from="*"></assign>

</input>

</operation>

 

</sequence>

</onFault>

</sequence>

</process>

 

How to implement inbound Socket connection from remote Socket Server to Sterling B2B Integrator?

  • Configure the Socket Server Adapter.

image

 

The above Socket Server Adapter invokes a business process when the connection is established with the Socket Server Adapter.

  • Write a business process.

 

The sample business process when executed successfully displays "This data is used for testing" at the client.

 

<process name="mk_socketserverdemo">

<sequence>

<assign name="Assign" to="testNode">This data is used for testing</assign>

<operation name="SocketWriteServiceType">

<participant name="SocketWriteService"/>

<output message="SocketWriteServiceTypeInputMessage">

<assign to="." from="*"></assign>

<assign to="NodeToRead" from="/ProcessData/testNode/text()"></assign>

</output>

<input message="inmsg">

<assign to="." from="*"></assign>

</input>

</operation>

 

<operation name="SocketCloseServiceType">

<participant name="SocketCloseService"/>

<output message="SocketCloseServiceTypeInputMessage">

<assign to="." from="*"></assign>

</output>

<input message="inmsg">

<assign to="." from="*"></assign>

</input>

</operation>

 

</sequence>

</process>

 

image

 

FAQ

  • What is EndOfData in Socket Read Service?

 

Indicates the end of data pattern. This is a sequence of byte values separated by |. If the EndOfData is specified as 97|87, the data from the socket is read till the data matches 97|87.

The maximum size of the pattern that can be specified as EndOfData is 255 characters.

Note that EndOfData does not support control characters except 'CR' and 'LF'.

 

  • What is BytesCount in Socket Read Service?

If you know the size of the data to be read, you can use the BytesCount. If you do not know the size of the data to be read from the Socket, use EndOfData.

 

  • Will I be able to use external perimeter server using Socket Client Services?

Yes. Socket Client Adapter support communication using Perimeter Server.

 

  • Does the Socket Client Services has support of SSL?

Yes. Socket Connect Service provide the option of using SSL.

 

  • Will I be able to execute custom java code instead of Business Process using Socket Server Adapter?

Yes. The Socket Server Adapter provide you an option of executing custom Java code OR the business process.

 

Do you have questions or comments on the blog?

Please use comments section of the blog.

 

 

 

 

[{"Business Unit":{"code":"BU059","label":"IBM Software w\/o TPS"},"Product":{"code":"SS3JSW","label":"IBM Sterling B2B Integrator"},"Component":"","Platform":[{"code":"PF025","label":"Platform Independent"}],"Version":"","Edition":"","Line of Business":{"code":"LOB59","label":"Sustainability Software"}}]

UID

ibm11120755