Example usage for java.nio.channels AsynchronousSocketChannel read

List of usage examples for java.nio.channels AsynchronousSocketChannel read

Introduction

In this page you can find the example usage for java.nio.channels AsynchronousSocketChannel read.

Prototype

@Override
public final <A> void read(ByteBuffer dst, A attachment, CompletionHandler<Integer, ? super A> handler) 

Source Link

Usage

From source file:Main.java

@Override
public void completed(AsynchronousSocketChannel client, Attachment attach) {
    try {//  www . j a va  2 s.  c om
        SocketAddress clientAddr = client.getRemoteAddress();
        System.out.format("Accepted a  connection from  %s%n", clientAddr);
        attach.server.accept(attach, this);
        ReadWriteHandler rwHandler = new ReadWriteHandler();
        Attachment newAttach = new Attachment();
        newAttach.server = attach.server;
        newAttach.client = client;
        newAttach.buffer = ByteBuffer.allocate(2048);
        newAttach.isRead = true;
        newAttach.clientAddr = clientAddr;
        client.read(newAttach.buffer, newAttach, rwHandler);
    } catch (IOException e) {
        e.printStackTrace();
    }
}