当前位置: 代码迷 >> J2SE >> NIO有关问题
  详细解决方案

NIO有关问题

热度:85   发布时间:2016-04-24 01:50:35.0
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事件。
  相关解决方案