Example usage for java.nio.channels AsynchronousServerSocketChannel accept

List of usage examples for java.nio.channels AsynchronousServerSocketChannel accept

Introduction

In this page you can find the example usage for java.nio.channels AsynchronousServerSocketChannel accept.

Prototype

public abstract <A> void accept(A attachment, CompletionHandler<AsynchronousSocketChannel, ? super A> handler);

Source Link

Document

Accepts a connection.

Usage

From source file:Main.java

public static void main(String[] args) throws Exception {
    AsynchronousServerSocketChannel server = AsynchronousServerSocketChannel.open();
    String host = "localhost";
    int port = 8989;
    InetSocketAddress sAddr = new InetSocketAddress(host, port);
    server.bind(sAddr);//from www.  java  2 s .c o m
    System.out.format("Server is listening at %s%n", sAddr);
    Attachment attach = new Attachment();
    attach.server = server;
    server.accept(attach, new ConnectionHandler());
    Thread.currentThread().join();
}