我有一个tcp客户端 - 服务器应用程序,其中客户端打开一个用于一次性连接并在配置时间后断开连接的连接。我如何配置它始终保持连接的活动状态,在关闭的连接上重新连接并确保多个客户端连接对服务器开放。配置保持活动状态始终保持连接状态
客户端配置:
<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}" />
服务器配置:
<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 = false达到了我所期望的。但是,如果服务器重新启动,我如何保证客户端会自动连接? – xjava
如果当前连接已关闭,则在发送下一条消息时将自动创建新连接。 –
感谢@加里宝贵的建议。 – xjava