first one :
1 2 3 4 5
| final ServerSocketChannel sss = ServerSocketChannel.open(); sss.configureBlocking(false); sss.socket().bind(new InetSocketAddress(port)); final Selector selector = Selector.open(); sss.register(selector, SelectionKey.OP_CONNECT|SelectionKey.OP_ACCEPT); |
the last lines throws an illegalargumentexception, no matter what the ops is.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| public ConnectionTarget openConnection(String ip, int port) { InetSocketAddress socketAddress = new InetSocketAddress(ip, port); try { SocketChannel sc = SocketChannel.open(); sc.configureBlocking(false); sc.connect(socketAddress); ConnectionTarget ct = new ConnectionTarget(sc.socket().getInetAddress(), this); lOpenConnections.add(ct); mOpenConnections.put(ct, sc); sc.register(metaSelector, SelectionKey.OP_READ); if (debug) { System.out.println("Connected to "+ip+':'+port); } return ct; } catch (IOException e) { handleException(e); return null; } } |
this time, the line
sc.register(metaSelector, SelectionKey.OP_READ);
blocks. forever.
what is going on ? (i'm using jdk 1.5)