Files
spring-integration-samples/basic/tcp-client-server
Gunnar Hillert 85bef285d4 INTSAMPLES-47 - Upgrade SI dep. to 2.1.0.RELEASE
* Upgraded all Spring Integration dependencies to 2.1.0.RELEASE
* All Samples use the new Artifactory-based Milestone Repository http://repo.springsource.org/milestone (As the repositories are additive, this repository will also include the release repo)
* Added versions to all Maven plugin declarations, reducing the amount WARNING-level logging substantially
2012-01-07 22:58:10 -05:00
..

This is a place to get started with tcp. It demonstrates a simple message flow represented by the diagram below:

Gateway -> Channel -> TcpOutboundGateway -> <===Socket===> -> TcpInboundGateway -> Channel -> ServiceActivator

The service returns a response which the inbound gateway sends back over the socket to the outbound gateway
and the result is returned to the client that invoked the original SimpleGateway method. 

To run sample simply execute a test case in org.springframework.integration.samples.tcpclientservice package.

Note that the test case includes an alternative configuration that uses the in-built conversion service
and the channel dataType attribute, instead of explicit transformers, to convert from byte arrays to Strings.

Simply change the @ContextConfiguration to switch between the two techniques.

In addition, a simple telnet server is provided; see TelnetServer in src/main/java. Run this class as a
java application and then use telnet to connect to the service ('telnet localhost 11111'). 

Messages sent will be returned, preceded by 'echo:'.


$ telnet localhost 11111
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
Hello world!
echo:Hello world!
Test
echo:Test
^]

telnet> quit
Connection closed.


Note that the test case also demonstrates error handling on an inbound gateway using direct channels.
If the payload is 'FAIL', the EchoService throws an exception. The gateway is configured
with an error-channel attribute. Messages sent to that channel are consumed by a transformer
that concatenates the inbound message payload with the message text from the thrown 
exception, returning 'FAIL:Failure Demonstration' over the TCP socket.

This can also be demonstrated with the telnet client thus...

$ telnet localhost 11111
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
Hello world!
echo:Hello world!
FAIL
FAIL:Failure Demonstration
Hello
echo:Hello
^]

telnet> quit
Connection closed.