Example usage for java.nio.channels AsynchronousServerSocketChannel bind

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

Introduction

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

Prototype

public final AsynchronousServerSocketChannel bind(SocketAddress local) throws IOException 

Source Link

Document

Binds the channel's socket to a local address and configures the socket to listen for connections.

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);
    System.out.format("Server is listening at %s%n", sAddr);
    Attachment attach = new Attachment();
    attach.server = server;/*  w w w  . j  av  a  2  s .c o m*/
    server.accept(attach, new ConnectionHandler());
    Thread.currentThread().join();
}