org.apache.mina.transport.socket.DatagramAcceptor Java Examples

The following examples show how to use org.apache.mina.transport.socket.DatagramAcceptor. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestDnsServer.java    From netty-4.1.22 with Apache License 2.0 6 votes vote down vote up
@Override
public void start() throws IOException {
    InetSocketAddress address = new InetSocketAddress(NetUtil.LOCALHOST4, 0);
    UdpTransport transport = new UdpTransport(address.getHostName(), address.getPort());
    setTransports(transport);

    DatagramAcceptor acceptor = transport.getAcceptor();

    acceptor.setHandler(new DnsProtocolHandler(this, store) {
        @Override
        public void sessionCreated(IoSession session) throws Exception {
            // USe our own codec to support AAAA testing
            session.getFilterChain()
                .addFirst("codec", new ProtocolCodecFilter(new TestDnsProtocolUdpCodecFactory()));
        }
    });

    ((DatagramSessionConfig) acceptor.getSessionConfig()).setReuseAddress(true);

    // Start the listener
    acceptor.bind();
}
 
Example #2
Source File: TestDnsServer.java    From servicetalk with Apache License 2.0 6 votes vote down vote up
@Override
public void start() throws IOException {
    InetSocketAddress address = AddressUtils.localAddress(0);
    UdpTransport transport = new UdpTransport(address.getHostString(), address.getPort());
    setTransports(transport);

    DatagramAcceptor acceptor = transport.getAcceptor();

    acceptor.setHandler(new DnsProtocolHandler(this, store) {
        @Override
        public void sessionCreated(IoSession session) {
            // Use our own codec to support AAAA testing
            session.getFilterChain()
                    .addFirst("codec", new ProtocolCodecFilter(new TestDnsProtocolUdpCodecFactory()));
        }
    });

    ((DatagramSessionConfig) acceptor.getSessionConfig()).setReuseAddress(true);

    // Start the listener
    acceptor.bind();
}