1
votes

I'm trying to create a Camel/Netty TCP client that works as follows:

  1. connect to remoteserver:1234
  2. send a handshake message (pretend it's the string "handshake")
  3. leave this connection open
  4. wait/listen for TCP messages from the server and reply to them

Here's a simple hello-world server.

    from("netty:tcp://localhost:8001?textline=true&sync=true") //
            .process((exchange) -> {
                String msgReceived = exchange.getIn().getBody(String.class);
                exchange.getOut().setBody("hello " + msgReceived);
            });

I can open a command line TCP connection to this, type in text, and receive my hello-world reply.

Now how do I structure an analogous client that likewise just waits for messages and replies?

1
Using camel for a client like this is not going to work. Remember Camel routes have message exchange patterns of IN/OUT and IN Only i.e. request/reply and request only. If you need a client like this just use plain netty.Namphibian
There is a clientMode=true option you can set - see the documentationClaus Ibsen

1 Answers

0
votes

When you say "wait/listen for TCP messages from the server and reply to them" you are reversing the roles, now the client acts like a server and the server like a client.

What you could do is set up an incoming route in the client listening on a given port and use the initial handshake message to the server to communicate the client's IP and port.