title: Send and receive data using Spring Integration TCP IP socket
body: <p>I am creating a simple spring boot application(PoC) to send product id's (string) from client to server over socket using Spring integration TCP. If the server is hit with correct product data, the server will respond back with the product details which I need to print. Just need to establish a connection and get the response by sending proper data. </p>
  
  <p>Please tell me what are the classes I am supposed to implement? outbound/inboud gateways,messsage channels, tcplisteners? Should I go with xml configuration or annotations? I am new to SI and would be of great help if you could give me an idea on how to implement it. </p>
  
  <hr>
  
  <p>Here is my updated integration xml.
      </p>
  
  <pre><code>&lt;int-ip:tcp-connection-factory id="client" type="client" host="XX.XX.XX.99" port="9XXX" single-use="true" so-timeout="10000" /&gt;
  
  &lt;int:channel id="input"/&gt;
  
  &lt;int-ip:tcp-outbound-gateway id="outGateway" request-channel="input" reply-channel="clientBytes2StringChannel" connection-factory="client" request-timeout="10000" reply-timeout="10000"/&gt;
  
  &lt;int:object-to-string-transformer id="clientBytes2String" input-channel="clientBytes2StringChannel"/&gt; 
  
  &lt;int:service-activator input-channel="clientBytes2StringChannel" ref="echoService" method="test"/&gt; 
  
  &lt;bean id="echoService" class="org.springframework.integration.samples.tcpclientserver.EchoService"/&gt;
  
  &lt;int:channel id="toSA"/&gt;
  </code></pre>
  
  <p>But this still prints the echoed result. Also, when I call getHost on abstractClientConnectionfactory from main class, its showing "localhost". How can I confirm if the connection is active?</p>
  
  <hr>
  
  <pre><code>&lt;int:gateway id="gw"
               service-interface="org.springframework.integration.samples.tcpclientserver.SimpleGateway"
               default-request-channel="input"/&gt;
  
  &lt;int-ip:tcp-connection-factory id="client" type="client" host="xx.xx.xx.99"
                           port="9xxx"
                           single-use="false" so-timeout="300000" using-nio="false"
                           so-keep-alive="true" serializer="byteArrayRawSerializer"
                               deserializer="byteArrayRawSerializer"/&gt;
  
  
  &lt;bean id="byteArrayRawSerializer" class="org.springframework.integration.ip.tcp.serializer.ByteArrayRawSerializer" /&gt;
  
  
  &lt;int-ip:tcp-outbound-gateway id="outGateway"
                               request-channel="input"
                               reply-channel="responseBytes2StringChannel"
                               connection-factory="client"
                               request-timeout="10000"
                               reply-timeout="10000" /&gt;
  
  &lt;int:object-to-string-transformer id="clientBytes2String"
                                    input-channel="responseBytes2StringChannel" output-channel="toSA"/&gt;
  
  
  &lt;int:service-activator input-channel="toSA" ref="echoService" method="test"/&gt; 
  
  &lt;bean id="echoService" class="org.springframework.integration.samples.tcpclientserver.EchoService"/&gt;
  
  &lt;int:channel id="toSA"/&gt; 
  
  &lt;int:transformer id="errorHandler" input-channel="errorChannel" expression="payload.failedMessage.payload + ':' + payload.cause.message"/&gt;
  &lt;int:channel id="responseBytes2StringChannel"&gt;&lt;/int:channel&gt;
  </code></pre>
  
  <p>**** Update SI xml ****
      </p>
  
  <pre><code>&lt;int:gateway id="gw"
               service-interface="org.springframework.integration.samples.tcpclientserver.SimpleGateway"
               default-request-channel="objectIn"/&gt;
  
  &lt;int:channel id="objectIn" /&gt;
  
  &lt;int-ip:tcp-connection-factory id="client"
                                 type="client"
                                 host="xx.xx.xx.99"
                                 port="9xxx"
                                 single-use="true"
                                 so-timeout="50000"
                                 using-nio="false"
                                 so-keep-alive="true"/&gt;
                                 &lt;!-- 
                                 serializer="byteArrayLengthSerializer"
                                 deserializer="byteArrayLengthSerializer"
  
  &lt;bean id="byteArrayLengthSerializer" class="org.springframework.integration.ip.tcp.serializer.ByteArrayLengthHeaderSerializer " /&gt;
  --&gt;
  &lt;int:payload-serializing-transformer input-channel="objectIn" output-channel="objectOut"/&gt;
  
  &lt;int-ip:tcp-outbound-gateway id="outGateway"
                               request-channel="objectOut"
                               reply-channel="bytesIn"
                               connection-factory="client"
                               request-timeout="10000"
                               reply-timeout="10000"
                                /&gt;
  
  &lt;int:payload-deserializing-transformer input-channel="bytesIn" output-channel="objectOut" /&gt;
  
  &lt;int:object-to-string-transformer id="clientBytes2String"
                                    input-channel="objectOut" output-channel="toSA"/&gt;
  
  
  
  &lt;int:service-activator input-channel="toSA" ref="echoService" method="test"/&gt; 
  
  &lt;bean id="echoService" class="org.springframework.integration.samples.tcpclientserver.EchoService"/&gt;
  
  &lt;int:channel id="objectOut"/&gt; 
  &lt;int:channel id="toSA"/&gt; 
  &lt;int:channel id="bytesIn"/&gt; 
  </code></pre>