Java New IO
Selector感兴趣的事件
SelectionKey.OP_ACCEPT();
SelectionKey.OP_CONNECT();
SelectionKey.OP_READ();
SelectionKey.OP_WRITE();
init()
Selector selector=Selector.open();
ServerSocketChannel channel=ServerSocketChannel.open();
channel.configureBlocking(false);
ServerSocket socket=channel.socket();
socket.bind(new InetSocketAddress(port));
socket.register(selector,SelectionKey.OP_ACCEPT);
Listen()
while(true){
selector.select();
Iterator i=selector.selectedKeys().iterator();
While(i.hasNext()){
SelectionKey key=i.next();
i.remove();
If(key.isAcceptable()){
}else if(key.isReadable()){
}
}
read(SelectionKey key)
}
原文:https://www.cnblogs.com/ttaall/p/11991300.html