Package java.nio.channels

Examples of java.nio.channels.AsynchronousServerSocketChannel.accept()


            AsynchronousServerSocketChannel socket = AsynchronousServerSocketChannel.open(group);
            socket.setOption(StandardSocketOptions.SO_REUSEADDR, Boolean.TRUE);
            socket.bind(address, backlog);
            SocketAddress local = socket.getLocalAddress();
            channels.put(local, socket);
            socket.accept(local, new AcceptCompletionHandler(socket));
        }
    }

    public void bind(SocketAddress address) throws IOException {
        bind(Collections.singleton(address));
View Full Code Here


            AsynchronousServerSocketChannel socket = AsynchronousServerSocketChannel.open(group);
            socket.setOption(StandardSocketOptions.SO_REUSEADDR, Boolean.TRUE);
            socket.bind(address, backlog);
            SocketAddress local = socket.getLocalAddress();
            channels.put(local, socket);
            socket.accept(local, new AcceptCompletionHandler(socket));
        }
    }

    public void bind(SocketAddress address) throws IOException {
        bind(Collections.singleton(address));
View Full Code Here

            AsynchronousServerSocketChannel socket = AsynchronousServerSocketChannel.open(group);
            socket.setOption(StandardSocketOptions.SO_REUSEADDR, Boolean.TRUE);
            socket.bind(address, backlog);
            SocketAddress local = socket.getLocalAddress();
            channels.put(local, socket);
            socket.accept(local, new AcceptCompletionHandler(socket));
        }
    }

    public void bind(SocketAddress address) throws IOException {
        bind(Collections.singleton(address));
View Full Code Here

    public void testAsyncSocketChannel() throws Exception
    {
        AsynchronousServerSocketChannel connector = AsynchronousServerSocketChannel.open();
        connector.bind(null);
        InetSocketAddress addr=(InetSocketAddress)connector.getLocalAddress();
        Future<AsynchronousSocketChannel> acceptor = connector.accept();
       
        AsynchronousSocketChannel client = AsynchronousSocketChannel.open();
       
        client.connect(new InetSocketAddress("127.0.0.1",addr.getPort())).get(5, TimeUnit.SECONDS);
View Full Code Here

        System.out.println("Listening for connections on port " + port);
        final AsynchronousServerSocketChannel serverChannel = AsynchronousServerSocketChannel.open();
        InetSocketAddress address = new InetSocketAddress(port);
        serverChannel.bind(address);
        final CountDownLatch latch = new CountDownLatch(1);
        serverChannel.accept(null, new CompletionHandler<AsynchronousSocketChannel, Object>() {
            @Override
            public void completed(final AsynchronousSocketChannel channel, Object attachment) {
                serverChannel.accept(null, this);
                ByteBuffer buffer = ByteBuffer.allocate(100);
                channel.read(buffer, buffer, new EchoCompletionHandler(channel));
View Full Code Here

        serverChannel.bind(address);
        final CountDownLatch latch = new CountDownLatch(1);
        serverChannel.accept(null, new CompletionHandler<AsynchronousSocketChannel, Object>() {
            @Override
            public void completed(final AsynchronousSocketChannel channel, Object attachment) {
                serverChannel.accept(null, this);
                ByteBuffer buffer = ByteBuffer.allocate(100);
                channel.read(buffer, buffer, new EchoCompletionHandler(channel));
            }

            @Override
View Full Code Here

        channelGroup = AsynchronousChannelGroup.withThreadPool(Executors.newFixedThreadPool(5));
        final AsynchronousServerSocketChannel server = AsynchronousServerSocketChannel.open(channelGroup);
        server.bind(new InetSocketAddress(5000));
        Stopwatch stopwatch = new Stopwatch().start();
        while (!channelGroup.isShutdown()) {
            AsynchronousSocketChannel socket = server.accept().get();
            processConnection(socket);
        }
        stopwatch.stop();
        System.out.println("EchoServer is done in " + stopwatch.elapsedMillis());
    }
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. 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.