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

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


        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


  public static final int PORT = 33789;

  public static void main(String[] args) throws IOException
  {
    ImageServerIoHandler handler = new ImageServerIoHandler();
    SocketAcceptor acceptor = new SocketAcceptor();
    acceptor.getFilterChain().addLast("protocol", new ProtocolCodecFilter(new ImageCodecFactory(false)));
    acceptor.bind(new InetSocketAddress(PORT), handler);
    System.out.println("server is listenig at port " + PORT);
  }
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

            }
        }

        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

*/
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

    /** 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

        IoConnector connector = new VmPipeConnector();
        return new MinaEndpoint(uri, this, address, acceptor, connector, null);
    }

    protected MinaEndpoint createSocketEndpoint(String uri, URI connectUri) {
        IoAcceptor acceptor = new SocketAcceptor();
        SocketAddress address = new InetSocketAddress(connectUri.getHost(), connectUri.getPort());
        IoConnector connector = new SocketConnector();

        // TODO customize the config via URI
        SocketConnectorConfig config = new SocketConnectorConfig();
View Full Code Here

        IoConnector connector = new VmPipeConnector();
        return new MinaEndpoint(uri, this, address, acceptor, null, connector, null, false, 0, false, false);
    }

    protected MinaEndpoint createSocketEndpoint(String uri, URI connectUri, Map parameters) {
        IoAcceptor acceptor = new SocketAcceptor();
        SocketAddress address = new InetSocketAddress(connectUri.getHost(), connectUri.getPort());
        IoConnector connector = new SocketConnector();

        // connector config
        SocketConnectorConfig connectorConfig = new SocketConnectorConfig();
View Full Code Here

        return endpoint;
    }

    protected MinaEndpoint createSocketEndpoint(String uri, URI connectUri, Map parameters) {
        IoAcceptor acceptor = new SocketAcceptor();
        SocketAddress address = new InetSocketAddress(connectUri.getHost(), connectUri.getPort());
        IoConnector connector = new SocketConnector();

        // connector config
        SocketConnectorConfig connectorConfig = new SocketConnectorConfig();
View Full Code Here

TOP

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

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.