Package org.apache.mina.transport.nio

Examples of org.apache.mina.transport.nio.NioUdpServer


     */
    @Override
    public void start(int port) throws IOException {
        UdpSessionConfig config = new DefaultUdpSessionConfig();
        config.setReadBufferSize(65536);
        udpServer = new NioUdpServer(config);
        udpServer.setIoHandler(new IoHandler() {
            @Override
            public void sessionOpened(IoSession session) {
                session.setAttribute(STATE_ATTRIBUTE, State.WAIT_FOR_FIRST_BYTE_LENGTH);
            }
View Full Code Here


    static final Logger LOG = LoggerFactory.getLogger(NioUdpEchoServer.class);

    public static void main(final String[] args) {
        LOG.info("starting echo server");

        final NioUdpServer server = new NioUdpServer();

        // create the filter chain for this service
        server.setFilters(new LoggingFilter("LoggingFilter1"), new IoFilter() {

            @Override
            public void sessionOpened(final IoSession session) {
                LOG.info("session {} open", session);
            }

            @Override
            public void sessionIdle(final IoSession session, final IdleStatus status) {
                LOG.info("session {} idle", session);
            }

            @Override
            public void sessionClosed(final IoSession session) {
                LOG.info("session {} open", session);
            }

            @Override
            public void messageWriting(final IoSession session, WriteRequest message,
                    final WriteFilterChainController controller) {
                // we just push the message in the chain
                controller.callWriteNextFilter(message);
            }

            @Override
            public void messageReceived(final IoSession session, final Object message,
                    final ReadFilterChainController controller) {

                if (message instanceof ByteBuffer) {
                    LOG.info("echoing");
                    session.write(message);
                }
            }

            @Override
            public void messageSent(final IoSession session, final Object message) {
                LOG.info("message {} sent", message);
            }
        });

        server.setIoHandler(new AbstractIoHandler() {
            @Override
            public void sessionOpened(final IoSession session) {
                LOG.info("session opened {}", session);

                final String welcomeStr = "welcome\n";
                final ByteBuffer bf = ByteBuffer.allocate(welcomeStr.length());
                bf.put(welcomeStr.getBytes());
                bf.flip();
                session.write(bf);

            }
        });

        try {
            final SocketAddress address = new InetSocketAddress(9999);
            server.bind(address);
            LOG.debug("Running the server for 25 sec");
            Thread.sleep(25000);
            LOG.debug("Unbinding the UDP port");
            server.unbind();
        } catch (final InterruptedException e) {
            LOG.error("Interrupted exception", e);
        }
    }
View Full Code Here

    }

    public static void main(final String[] args) {
        LOG.info("starting echo server");

        final NioUdpServer server = new NioUdpEchoServer();

        // create the filter chain for this service
        server.setFilters(new LoggingFilter("LoggingFilter1"), ((NioUdpEchoServer) server).new UdpEchoFilter());

        server.setIoHandler(new AbstractIoHandler() {
            @Override
            public void sessionOpened(final IoSession session) {
                LOG.info("session opened {}", session);

                final String welcomeStr = "welcome\n";
                final ByteBuffer bf = ByteBuffer.allocate(welcomeStr.length());
                bf.put(welcomeStr.getBytes());
                bf.flip();
                session.write(bf);

            }
        });

        try {
            final SocketAddress address = new InetSocketAddress(9999);
            server.bind(address);
            LOG.debug("Running the server for 25 sec");
            Thread.sleep(25000);
            LOG.debug("Unbinding the UDP port");
            server.unbind();
        } catch (final InterruptedException e) {
            LOG.error("Interrupted exception", e);
        }
    }
View Full Code Here

     */
    @Override
    public void start(int port) throws IOException {
        UdpSessionConfig config = new DefaultUdpSessionConfig();
        config.setReadBufferSize(65536);
        udpServer = new NioUdpServer(config);
        udpServer.setIoHandler(new IoHandler() {
            @Override
            public void sessionOpened(IoSession session) {
                session.setAttribute(STATE_ATTRIBUTE, State.WAIT_FOR_FIRST_BYTE_LENGTH);
            }
View Full Code Here

TOP

Related Classes of org.apache.mina.transport.nio.NioUdpServer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.