- AsynchronousServerSocketChannel
服务端Socket通道类,负责服务端Socket的创建和监听;
用法示例:
final AsynchronousServerSocketChannel listener =
AsynchronousServerSocketChannel.open().bind(new InetSocketAddress(5000));
listener.accept(null, new CompletionHandler<AsynchronousSocketChannel,Void>() {
public void completed(AsynchronousSocketChannel ch, Void att) {
// accept the next connection
listener.accept(null, this);
// handle this connection
handle(ch);
}
public void failed(Throwable exc, Void att) {
...
}
});
- AsynchronousSocketChannel
客户端Socket通道类,负责客户端消息读写;
//AsynchronousSocketChannel open有两个重载方法
//打开异步套接字通道。
public static AsynchronousSocketChannel open(AsynchronousChannelGroup group)
throws IOException
public static AsynchronousSocketChannel open()
throws IOException
- CompletionHandler<A,V>
消息处理回调接口,是一个负责消费异步IO操作结果的消息处理器;