日期:2014-05-20  浏览次数:20779 次

NIO问题
有这么一段代码
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在那句代码中时什么意思了?

------解决方案--------------------
同时监视OP_READ和OP_WRITE事件。