Package java.nio.channels

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


    public void bind(Collection<? extends SocketAddress> addresses) throws IOException {
        for (SocketAddress address : addresses) {
            logger.debug("Binding Nio2Acceptor to address {}", address);
            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));
        }
    }
View Full Code Here


    public void bind(Collection<? extends SocketAddress> addresses) throws IOException {
        for (SocketAddress address : addresses) {
            logger.debug("Binding Nio2Acceptor to address {}", address);
            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));
        }
    }
View Full Code Here

    public void bind(Collection<? extends SocketAddress> addresses) throws IOException {
        for (SocketAddress address : addresses) {
            logger.debug("Binding Nio2Acceptor to address {}", address);
            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));
        }
    }
View Full Code Here

    @Test
    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();
       
View Full Code Here

    }

    @Override
    protected void doBind(SocketAddress localAddress) throws Exception {
        AsynchronousServerSocketChannel ch = javaChannel();
        ch.bind(localAddress, config.getBacklog());
    }

    @Override
    protected void doBeginRead() {
        if (acceptInProgress) {
View Full Code Here

    public void serve(int port) throws IOException {
        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);
View Full Code Here

    static AsynchronousChannelGroup channelGroup;

    public static void main(String[] args) throws Exception {
        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);
        }
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.