有这么一段代码
private Selector selector; public NioClient(String sip,int port) {
try {
InetSocketAddress ip = new InetSocketAddress(sip, port);
SocketChannel channel = SocketChannel.open();
System.out.println("begin connect");
boolean flag = channel.connect(ip);
if (flag) {
channel.configureBlocking(false);
selector = Selector.open();
SelectionKey key = channel.register(selector, SelectionKey.OP_READ | SelectionKey.OP_WRITE); key.attach(new ClientHandler());
}
} catch (IOException ex) {
Logger.getLogger(NioClient.class.getName()).log(Level.SEVERE, null, ex);
System.exit(0);
}
}SelectionKey.OP_READ | SelectionKey.OP_WRITE在那句代码中时什么意思了?
private Selector selector; public NioClient(String sip,int port) {
try {
InetSocketAddress ip = new InetSocketAddress(sip, port);
SocketChannel channel = SocketChannel.open();
System.out.println("begin connect");
boolean flag = channel.connect(ip);
if (flag) {
channel.configureBlocking(false);
selector = Selector.open();
SelectionKey key = channel.register(selector, SelectionKey.OP_READ | SelectionKey.OP_WRITE); key.attach(new ClientHandler());
}
} catch (IOException ex) {
Logger.getLogger(NioClient.class.getName()).log(Level.SEVERE, null, ex);
System.exit(0);
}
}SelectionKey.OP_READ | SelectionKey.OP_WRITE在那句代码中时什么意思了?
channel.register(selector, SelectionKey.OP_READ);
channel.register(selector,SelectionKey.OP_WRITE);