我有一個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