Cal
Cal

Reputation: 21

How to handle read() first with spring integration TCP outbound gateway

I'm implementing a tcp client which will send request to a server and expect an response. But when the client 1st connect to the server, the server will send a hello msg, with tcp outbound gateway, it expects to send then receive. How can I do receive (only when first connect) then do my usually send and receive logic? And if I need to keep the connection alive, is there a way to send keep alive msg to the same connection by some scheduling task?

Upvotes: 0

Views: 711

Answers (1)

Gary Russell
Gary Russell

Reputation: 174769

Instead of a gateway use Collaborating Channel Adapters for completely async operations.

Collaborating adapters can also be used (server-side or client-side) for totally asynchronous communication (rather than with request/reply semantics).

You can use operating system keep alives (SO_KEEPALIVE). Or you can roll your own application-level keep alives with a polled inbound channel adapter...

<int:inbound-channel-adapter channel="toTcp" expression="'foo'">
    <int:poller fixed-delay="60000" />
</int:inbound-channel-adapter>

Upvotes: 0

Related Questions