List of usage examples for java.nio.channels AsynchronousSocketChannel getRemoteAddress
public abstract SocketAddress getRemoteAddress() throws IOException;
From source file:Main.java
@Override public void completed(AsynchronousSocketChannel client, Attachment attach) { try {//w w w . ja v a2s . co m 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(); } }