I'm implementing a DNS server using MINA (yes, I've looked at the one in
the directory project but no insight from that one since it only binds
to UDP). DNS servers should listen on both TCP and UDP (and in this case
it is required since some of the answers will blow out the UDP size
limits). Anyway, I'm having two problems;
1) Just to get the skeleton working I wanted to re-create the
ReverseProtocol example so that it worked on both UDP and TCP on the
same port. I have it binding and the logger shows the connections and
the packet contents but the ReverseProtocolHandler never sees the
packet. I've included the main class below. I haven't really modified
ReverseProtocolHandler from the example other than changing the package
name.
2) Conceptually I'm trying to wrap my head around how to connect the
session oriented TCP side and the non-session oriented datagram side
together in the CodecFilter so that the IoHandler just gets a DNS
question that it simply answers without regard to whether it was
received via TCP or UDP. Does anyone have any suggestions for how to
handle that within the CodecFilter? One of the things I'm really
confused by is the use of Session 'language' about the DatagramAcceptor
and what that means.
Thanks!
public class DnsServer {
private static final int PORT = 5300;
public static void main( String[] args ) throws Exception
{
IoAcceptor tcpacceptor = new SocketAcceptor();
IoAcceptor udpacceptor = new DatagramAcceptor();
// Prepare the configuration
SocketAcceptorConfig tcpcfg = new SocketAcceptorConfig();
DatagramAcceptorConfig udpcfg = new DatagramAcceptorConfig();
LoggingFilter loggingfilter = new LoggingFilter();
tcpcfg.setReuseAddress( true );
tcpcfg.getFilterChain().addLast( "logger", loggingfilter );
ProtocolCodecFilter codecFilter = new ProtocolCodecFilter(
new TextLineCodecFactory(Charset.forName("UTF-8")));
tcpcfg.getFilterChain().addLast(
"codec",
codecFilter);
udpcfg.getFilterChain().addLast( "logger", loggingfilter);
udpcfg.getFilterChain().addLast("codec", codecFilter);
// Bind
tcpacceptor.bind(
new InetSocketAddress( PORT ),
new ReverseProtocolHandler(),
tcpcfg );
udpacceptor.bind(
new InetSocketAddress( PORT ),
new ReverseProtocolHandler(),
udpcfg);
System.out.println( "Listening on port " + PORT );
}
}
--
Michael Mealling Refactored Networks, LLC
CEO & President refactored-networks.com
Office: +1-678-581-9656 Cell: +1-678-640-6884
LinkedIn: http://www.linkedin.com/in/mealling