You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by Hardik Kubavat <ha...@primavera-software.com> on 2013/12/18 09:34:30 UTC

MINA Handler for UDP & TCP

Can we Use Same Handler Object for UDP & TCP Acceptor and Connector?
Is causing problem or not?

Re: MINA Handler for UDP & TCP

Posted by Emmanuel Lécharny <el...@gmail.com>.
Le 12/18/13 9:34 AM, Hardik Kubavat a écrit :
> Can we Use Same Handler Object for UDP & TCP Acceptor and Connector?
> Is causing problem or not?
Good question !

Yes, you can share a Handler for UDP and TCP acceptor, but it's unlikely
that it will work well if you share the handler between a connector and
an accceptor, unless your protocol is totally symetric. Now, understand
that a session opened on TCP will not be shared with the UDP session
(they will be two different session).

For the record, the Apache Directory Kerberos server is using TCP and
UDP with the same handler :

        // Kerberos can use UDP or TCP
        for ( Transport transport : transports )
        {
            IoAcceptor acceptor = transport.getAcceptor();

            // Now, configure the acceptor
            // Inject the chain
            IoFilterChainBuilder chainBuilder = new
DefaultIoFilterChainBuilder();

            if ( transport instanceof TcpTransport )
            {
                // Now, configure the acceptor
                // Disable the disconnection of the clients on unbind
                acceptor.setCloseOnDeactivation( false );

                // No Nagle's algorithm
                ( ( NioSocketAcceptor ) acceptor
).getSessionConfig().setTcpNoDelay( true );

                // Allow the port to be reused even if the socket is in
TIME_WAIT state
                ( ( NioSocketAcceptor ) acceptor ).setReuseAddress( true );
            }

            // Inject the codec
            ( ( DefaultIoFilterChainBuilder ) chainBuilder ).addFirst(
"codec",
                new ProtocolCodecFilter(
                    KerberosProtocolCodecFactory.getInstance() ) );

            acceptor.setFilterChainBuilder( chainBuilder );

            // Inject the protocol handler
            acceptor.setHandler( new KerberosProtocolHandler( this,
store ) );

            // Bind to the configured address
            acceptor.bind();
        }


-- 
Regards,
Cordialement,
Emmanuel Lécharny
www.iktek.com