Hi
I am trying to use ReadFuture on the server side to receive a second input
message after a first one has been received with the following IoHandler.
(This is a reduced problem from a more complex design and architecture).
When connecting to this server with a standard telnet client and typing 2
"return", only the 2 characters 0x0D0A of the first "return" are received
and the future.await() blocks. What did I miss in this code??
Here the log:
Listening on port 23
R: 0.0, W: 0.0
R: 0.0, W: 0.0
[16:58:08] INFO [org.apache.mina.example.echoserver.EchoProtocolHandler] -
OPENED
[16:58:10] INFO [org.apache.mina.example.echoserver.EchoProtocolHandler] -
Received : HeapBuffer[pos=0 lim=2 cap=2048: 0D 0A]
R: 0.0, W: 0.0
R: 0.0, W: 0.0
R: 0.0, W: 0.0
R: 0.0, W: 0.0
R: 0.0, W: 0.0
R: 0.0, W: 0.0
Here a snippet of the IoHandler
@Override
public void messageReceived(IoSession session, Object message) throws
Exception {
LOGGER.info("Received : " + message);
session.getConfig().setUseReadOperation(true);
ReadFuture future = session.read();
future.await();
Object object = future.getMessage();
LOGGER.info("Future :" + object);
session.write(((IoBuffer) object).duplicate());
session.getConfig().setUseReadOperation(false);
// Write the received data back to remote peer
session.write(((IoBuffer) message).duplicate());
}
The IoAcceptor is controlled in the Main class as
public static void main(String[] args) throws Exception {
SocketAcceptor acceptor = new NioSocketAcceptor();
acceptor.setReuseAddress(true);
DefaultIoFilterChainBuilder chain = acceptor.getFilterChain();
ExecutorFilter executorFilter = new ExecutorFilter();
chain.addLast("executor", executorFilter);
// Bind
acceptor.setHandler(new EchoProtocolHandler());
acceptor.bind(new InetSocketAddress(PORT));