Hi there,

I successfully used MINA with TCP transport. Now I want to be able to use
UDP too. But it seems, that messages above 2048byte size, are not read
properly.
Here's some logoutput showing the problem:

--log--
// client sends the message
2008-11-13 12:03:29,993 [INFO   ] t_id=14
org.apache.mina.filter.logging.LoggingFilter.log -> SENT: HeapBuffer[pos=0
lim=2406 cap=4096: 00 02 00 00 00 02 00 00 09 5C 00 06 73 65 72 76...]

// server receives it
2008-11-13 12:03:29,993 [INFO   ] t_id=13
org.apache.mina.filter.logging.LoggingFilter.log -> RECEIVED:
HeapBuffer[pos=0 lim=2048 cap=2048: 00 02 00 00 00 02 00 00 09 5C 00 06 73
65 72 76...]
2008-11-13 12:03:29,993 [FINEST ] t_id=13
de.root1.simon.codec.base.MsgInvokeDecoder.decodeBody ->
msgSizeInBytes=2396 position=10
2008-11-13 12:03:29,993 [FINEST ] t_id=13
de.root1.simon.codec.base.MsgInvokeDecoder.decodeBody -> need more data.
needed=2396 available=2038
--/log--

After that, the server waits and waits and waits. but there is no more data
coming and no more "RECEIVED:" log entry except the already shown...
Here's how I create the server side:

--code--
...
acceptor = new NioDatagramAcceptor();
if (acceptor instanceof NioDatagramAcceptor) {
        NioDatagramAcceptor nioDatagramAcceptor = (NioDatagramAcceptor)acceptor;
        logger.debug("setting 'ReuseAddress' on NioDatagramAcceptor");
        nioDatagramAcceptor.getSessionConfig().setReuseAddress(true);
        logger.debug("receive buffer
size={}",nioDatagramAcceptor.getSessionConfig().getReceiveBufferSize());
}
...
acceptor.getFilterChain().addLast("codec", new
ProtocolCodecFilter(protocolFactory));
        
acceptor.setHandler(dispatcher);
acceptor.getSessionConfig().setIdleTime( IdleStatus.BOTH_IDLE, 10 );
acceptor.bind(new InetSocketAddress(address, port));
--/code--

And the client side:

--code--
...
IoConnector connector = new NioDatagramConnector();
if (connector instanceof NioDatagramConnector) {
        NioDatagramConnector nioDatagramConnector =
(NioDatagramConnector)connector;
        logger.debug("setting 'ReuseAddress' on NioDatagramConnector");
        nioDatagramConnector.getSessionConfig().setReuseAddress(true);
}
connector.setHandler(dispatcher);
ConnectFuture future = connector.connect(new InetSocketAddress(host,
port));
future.awaitUninterruptibly(); // Wait until the connection attempt is
finished.
session = future.getSession();
session.getFilterChain().addLast("codec", new
ProtocolCodecFilter(protocolFactory));
...
--/code--

For the protocol, I use, as you can see, a ProtocolCodecFactory with well
defined message objects (like in the mina tutorials).

Here's how I receive the message with the MsgInvokeDecoder as seens in the
log above:

--code--
@Override
protected AbstractMessage decodeBody(IoSession session, IoBuffer in) {

        if (!readSize) {
                readSize  = true;
                msgSize = in.getInt();
                logger.trace("msgSizeInBytes={} position={}", msgSize,
in.position());
        }
        
        if (in.remaining() < msgSize) {
                logger.trace("need more data. needed={} available={}", msgSize,
in.remaining());
                return null;
        }
        MsgInvoke msgInvoke = new MsgInvoke();

        // read the full message ...
        // ...
        
        return msgInvoke;
    }
--/code--

For TCP this is all working fine. But for UDP not. Can someone point me to
the failure?!


best regards,
Alex

P.S. all buffers are still on default values with, I think 8k of size.


Reply via email to