first one :
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.
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)