Configure keep alive to keep connection alive all the time


I have a tcp client-server application where the client opens a connection which is for single use and disconnects after configured time. How can I configure it keep the connection alive all the time, reconnect on closed connection and ensure multiple clients connections are open to the server.

<strong>Client config:</strong>

<int-ip:tcp-connection-factory id="client" type="client" host="${server.TCP.host}" port="${server.TCP.port}" single-use="true" so-timeout="${client.TCP.socketTimeOut}" /> <int-ip:tcp-outbound-gateway id="outGateway" request-channel="bytesOut" reply-channel="bytesIn" connection-factory="client" request-timeout="${client.TCP.requestTimeOut}" reply-timeout="${client.TCP.replyTimeout}" />

<strong>Server config:</strong>

<int-ip:tcp-connection-factory id="tcpServerConnFactory" type="server" port="${service.tcp.port}" using-nio="true" single-use="false" so-timeout="${service.tcp.socketTimeout}" task-executor="taskExecutor"/> <int-ip:tcp-inbound-gateway id="tcpInboundGateway" connection-factory="tcpServerConnFactory" request-channel="bytesInChannel" reply-channel="bytesOutChannel" error-channel="errorChannel" />


Single use on the client side means exactly that - each socket is used for one request/reply then closed.

When single-use="false", one shared connection is used for all requests/replies - and each caller blocks waiting for the socket.

You can use a 'CachingClientConnectionFactory` to maintain a pool of permanent connections - see <a href="https://docs.spring.io/spring-integration/reference/html/ip.html#caching-cf" rel="nofollow">the documentation</a>.


As noted above, TCP sockets can be single-use (one request/response) or shared. Shared sockets do not perform well with outbound gateways, in high-volume environments, because the socket can only process one request/response at a time.

To improve performance, users could use collaborating channel adapters instead of gateways, but that requires application-level message correlation. See Section 31.8, “TCP Message Correlation” for more information.

Spring Integration 2.2 introduced a caching client connection factory, where a pool of shared sockets is used, allowing a gateway to process multiple concurrent requests with a pool of shared connections.


The upcoming 5.0 release - currently at milestone 7 (5.0.0.M7). Has a <a href="https://docs.spring.io/spring-integration/docs/5.0.0.M7/reference/html/ip.html#tcp-affinity-cf" rel="nofollow">Thread Affinity Connection Factory</a> which keeps a connection open per calling thread.


  • flex air httpservice stream error and timing out
  • Capitalization using PHP
  • Kubernetes on Rasperry Pi kube flannel CrashLoopBackOff and kube dns rpc error code = 2
  • How can I identify a specific item in and add a delete button each row in jquery
  • How to get NSLayoutConstraint's identifier by Its pointer?
  • glog verbose logging & Boost program options
  • How do I only display one element and not two based on lowest InternalPartyID?
  • Update-rc.d custom script running too late, and also runs at shutdown
  • Access a nested object array
  • how to group array of nsdictionary according to the value inside the element
  • Parse “key cannot be nil” error on [PFObject saveInBackground] (Cocoa)
  • How to use boost program_options to read an integer array?
  • Prestashop : loop on $product->save() method
  • e2e testing angular 7: Failed: Cannot read property 'fetchData' of undefined
  • How to get same result as following Mysql query from Solr?
  • NSURLCredentialStorage default credential not used automatically
  • In GTK, how do I change the localized language text on the UI while it's running?
  • App Script: How to view PDF of Google Sheet after function to save to Google Drive?
  • Pretty good heuristic evaluation rules for big TicTacToe 5x5 board
  • Receive .txt file from parse.com and place in textview
  • How to update all properties after store.sync()?
  • Inno Setup Search for specifc file on a CD, retrieve exact filepath and return value to [Files]-Sect
  • How to reply a tweet using the Twitter gem?
  • get latest text entry of GROUP BY statement
  • how to convert open xml representation of word document into RTF format using c#.net 4.0?
  • Python: sending key press events over SSH
  • Error in making a socket connection
  • Switch to popup in python using selenium
  • How to define and use opencv mat of user type
  • Ajax jQuery multiple calls at the same time - long wait for answer and not able to cancel
  • How to redirect a user to a different server and include HTTP basic authentication credentials?
  • Microsoft Visual Studio Community 2015 always crashes in Windows 10 if swithed to Visual FoxPro
  • Symfony2: How to get request parameter
  • Hazelcast - OperationTimeoutException
  • File upload with ng-file-upload throwing error
  • log4net write single file for each call to log.info
  • Getting error when using KSoap library to consume .NET web services
  • Busy indicator not showing up in wpf window [duplicate]
  • Why is Django giving me: 'first_name' is an invalid keyword argument for this function?
  • How can I use `wmic` in a Windows PE script?