0

I set up a server that receives messages over port xxx, but I want to respond to port yyy. Is there a simple way to achieve this?

My server:

    IoAcceptor acceptor = new NioSocketAcceptor();

    acceptor.setHandler(new MessageHandler());
    acceptor.getFilterChain().addLast("logger", new LoggingFilter());

    acceptor.getFilterChain().addLast("codec", new protocolCodecFilter(codecFactory));
    acceptor.getSessionConfig().setReadBufferSize(bufferSize);
    acceptor.bind(new InetSocketAddress(port));

The encode method of my encoder:

public void encode(IoSession session, Object message, ProtocolEncoderOutput out) throws Exception {
    byte[] writeBytes = (byte[]) message;       
    IoBuffer buffer = IoBuffer.allocate(writeBytes.length).setAutoExpand(false);
    buffer.put(writeBytes);
    buffer.flip();
    out.write(buffer);      
    writeMessage(session,writeBytes);
}

The msessage should be written to a different port. How do I achieve this?

1 Answers1

0

If you want to response message using different tcp port, you must make another other tcp connection first, which means you have two servers and tow clients.

     request

client1---------->server1

     reponse

server2---------->client2

Tuscany
  • 31
  • 5