Package org.apache.mina.transport.socket.nio

Examples of org.apache.mina.transport.socket.nio.SocketAcceptor$RegistrationRequest


            }
        }

        try {
            // Create an acceptor
            IoAcceptor acceptor = new SocketAcceptor();

            // Create a service configuration
            SocketAcceptorConfig cfg = new SocketAcceptorConfig();
            cfg.setReuseAddress(true);
            cfg.getFilterChain().addLast(
                    "protocolFilter",
                    new ProtocolCodecFilter(
                            new HttpServerProtocolCodecFactory()));
            cfg.getFilterChain().addLast("logger", new LoggingFilter());

            acceptor
                    .bind(new InetSocketAddress(port), new ServerHandler(), cfg);

            System.out.println("Server now listening on port " + port);
        } catch (Exception ex) {
            ex.printStackTrace();
View Full Code Here


    private static final int PORT = 8080;

    private static final boolean USE_SSL = false;

    public static void main(String[] args) throws Exception {
        IoAcceptor acceptor = new SocketAcceptor();
        IoAcceptorConfig config = new SocketAcceptorConfig();
        DefaultIoFilterChainBuilder chain = config.getFilterChain();

        ((SocketSessionConfig) config.getSessionConfig()).setReuseAddress(true);
        // Add SSL filter if SSL is enabled.
        if (USE_SSL) {
            addSSLSupport(chain);
        }

        // Bind
        acceptor.bind(new InetSocketAddress(PORT), new HttpProtocolHandler(),
                config);

        System.out.println("Listening on port " + PORT);
    }
View Full Code Here

        filter.setWriteBufferSize(1024);
        assertEquals(1024, filter.getWriteBufferSize());
    }

    public void testWriteUsingSocketTransport() throws Exception {
        IoAcceptor acceptor = new SocketAcceptor();
        ((SocketAcceptorConfig) acceptor.getDefaultConfig())
                .setReuseAddress(true);
        SocketAddress address = new InetSocketAddress("localhost",
                AvailablePortFinder.getNextAvailable());

        IoConnector connector = new SocketConnector();

        FixedRandomInputStream stream = new FixedRandomInputStream(
                4 * 1024 * 1024);

        SenderHandler sender = new SenderHandler(stream);
        ReceiverHandler receiver = new ReceiverHandler(stream.size);

        acceptor.bind(address, sender);

        synchronized (sender.lock) {
            synchronized (receiver.lock) {
                connector.connect(address, receiver);

                sender.lock.wait();
                receiver.lock.wait();
            }
        }

        acceptor.unbind(address);

        assertEquals(stream.bytesRead, receiver.bytesRead);
        assertEquals(stream.size, receiver.bytesRead);
        byte[] expectedMd5 = stream.digest.digest();
        byte[] actualMd5 = receiver.digest.digest();
View Full Code Here

    /** Set this to true if you want to make the server SSL */
    private static final boolean USE_SSL = false;

    public static void main(String[] args) throws Exception {
        IoAcceptor acceptor = new SocketAcceptor();
        IoAcceptorConfig config = new SocketAcceptorConfig();
        DefaultIoFilterChainBuilder chain = config.getFilterChain();

        // Add SSL filter if SSL is enabled.
        if (USE_SSL) {
            addSSLSupport(chain);
        }

        addLogger(chain);

        // Bind
        acceptor.bind(new InetSocketAddress(PORT), new EchoProtocolHandler(),
                config);

        System.out.println("Listening on port " + PORT);
    }
View Full Code Here

*/
public class Main {
    private static final int PORT = 8080;

    public static void main(String[] args) throws Exception {
        IoAcceptor acceptor = new SocketAcceptor();

        // Prepare the configuration
        SocketAcceptorConfig cfg = new SocketAcceptorConfig();
        cfg.setReuseAddress(true);
        cfg.getFilterChain().addLast("logger", new LoggingFilter());
        cfg.getFilterChain().addLast(
                "codec",
                new ProtocolCodecFilter(new TextLineCodecFactory(Charset
                        .forName("UTF-8"))));

        // Bind
        acceptor.bind(new InetSocketAddress(PORT),
                new ReverseProtocolHandler(), cfg);

        System.out.println("Listening on port " + PORT);
    }
View Full Code Here

    // Set this to false to use object serialization instead of custom codec.
    private static final boolean USE_CUSTOM_CODEC = true;

    public static void main(String[] args) throws Throwable {
        IoAcceptor acceptor = new SocketAcceptor();

        // Prepare the service configuration.
        SocketAcceptorConfig cfg = new SocketAcceptorConfig();
        cfg.setReuseAddress(true);
        if (USE_CUSTOM_CODEC) {
            cfg.getFilterChain()
                    .addLast(
                            "codec",
                            new ProtocolCodecFilter(
                                    new SumUpProtocolCodecFactory(true)));
        } else {
            cfg.getFilterChain().addLast(
                    "codec",
                    new ProtocolCodecFilter(
                            new ObjectSerializationCodecFactory()));
        }
        cfg.getFilterChain().addLast("logger", new LoggingFilter());

        acceptor.bind(new InetSocketAddress(SERVER_PORT),
                new ServerSessionHandler(), cfg);

        System.out.println("Listening on port " + SERVER_PORT);
    }
View Full Code Here

    SocketAddress socketAddress = new InetSocketAddress(PORT);

    protected void setUp() throws Exception {
        super.setUp();
        acceptor = new SocketAcceptor();
    }
View Full Code Here

        }

        try
        {
            // Create an acceptor
            IoAcceptor acceptor = new SocketAcceptor();
           
            // Create a service configuration
            SocketAcceptorConfig cfg = new SocketAcceptorConfig();
            cfg.setReuseAddress( true );
            cfg.getFilterChain().addLast(
                    "protocolFilter",
                    new ProtocolCodecFilter( new HttpServerProtocolCodecFactory() ) );
            cfg.getFilterChain().addLast( "logger", new LoggingFilter() );

            acceptor.bind( new InetSocketAddress( port ), new ServerHandler(), cfg );

            System.out.println( "Server now listening on port " + port );
        }
        catch( Exception ex )
        {
View Full Code Here

        final SSLFilter sslFilter =
            new SSLFilter( BogusSSLContextFactory.getInstance( true ) );

        boundAddress = null;
        datagramAcceptor = new DatagramAcceptor();
        socketAcceptor = new SocketAcceptor();
       
        ( ( DatagramSessionConfig ) datagramAcceptor.getDefaultConfig().getSessionConfig() ).setReuseAddress( true );
        ( ( SocketAcceptorConfig ) socketAcceptor.getDefaultConfig() ).setReuseAddress( true );
       
View Full Code Here

    /** Set this to true if you want to make the server SSL */
    private static final boolean USE_SSL = false;

    public static void main( String[] args ) throws Exception
    {
        IoAcceptor acceptor = new SocketAcceptor();
        IoAcceptorConfig config = new SocketAcceptorConfig();
        DefaultIoFilterChainBuilder chain = config.getFilterChain();
       
        // Add SSL filter if SSL is enabled.
        if( USE_SSL )
        {
            addSSLSupport( chain  );
        }
       
        addLogger( chain );
       
        // Bind
        acceptor.bind(
                new InetSocketAddress( PORT ),
                new EchoProtocolHandler(),
                config );

        System.out.println( "Listening on port " + PORT );
View Full Code Here

TOP

Related Classes of org.apache.mina.transport.socket.nio.SocketAcceptor$RegistrationRequest

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.