Package org.apache.mina.transport.nio

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


    /**
     * {@inheritDoc}
     */
    public void start(int port) throws IOException {
        tcpServer = new NioTcpServer();
        tcpServer.getSessionConfig().setReadBufferSize(128 * 1024);
        tcpServer.getSessionConfig().setTcpNoDelay(true);
        tcpServer.setIoHandler(new IoHandler() {
            public void sessionOpened(IoSession session) {
                session.setAttribute(STATE_ATTRIBUTE, State.WAIT_FOR_FIRST_BYTE_LENGTH);
View Full Code Here


public class HttpsTest {

    public static void main(String[] args) throws Exception {

        NioTcpServer httpServer = new NioTcpServer();

        httpServer.setFilters(new LoggingFilter("INCOMING"),
                new ProtocolCodecFilter<HttpPdu, ByteBuffer, Void, HttpDecoderState>(new HttpServerEncoder(),
                        new HttpServerDecoder()), new LoggingFilter("DECODED"), new DummyHttpSever());

        httpServer.getSessionConfig().setTcpNoDelay(true);

        // Make it use https, injecting a default SSLContext instance
        httpServer.getSessionConfig().setSslContext(BogusSslContextFactory.getInstance(true));

        httpServer.bind(new InetSocketAddress(8080));

        // run for 20 seconds
        Thread.sleep(20000);
        httpServer.unbind();

    }
View Full Code Here

public class HttpTest {

    public static void main(String[] args) throws Exception {

        NioTcpServer httpServer = new NioTcpServer();
        httpServer.setReuseAddress(true);
        httpServer.setFilters(new LoggingFilter("INCOMING"),
                new ProtocolCodecFilter<HttpPdu, ByteBuffer, Void, HttpDecoderState>(new HttpServerEncoder(),
                        new HttpServerDecoder()), new LoggingFilter("DECODED"), new DummyHttpSever());

        httpServer.getSessionConfig().setTcpNoDelay(true);

        httpServer.bind(new InetSocketAddress(8080));

        // run for 20 seconds
        Thread.sleep(20000);
        httpServer.unbind();

    }
View Full Code Here

    }

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

        NioTcpServer server = new NioTcpServer();
        MetricRegistry metrics = new MetricRegistry();
        JmxReporter reporter = JmxReporter.forRegistry(metrics).build();
        reporter.start();
        server.getSessionConfig().setIdleTimeInMillis(IdleStatus.READ_IDLE, 60 * 600 * 1000);
        server.getSessionConfig().setIdleTimeInMillis(IdleStatus.WRITE_IDLE, 60 * 600 * 1000);

        // create the filter chain for this service
        server.setFilters(new MonitoringFilter(metrics), new LoggingFilter("LoggingFilter1"),
                ((NioTcpEchoServerWithMonitoring) server).new TcpEchoFilter());
        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);

            }

            @Override
            public void exceptionCaught(IoSession session, Exception cause) {
                cause.printStackTrace();
            }
        });

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

TOP

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

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.