Java NIO channel never becomes readable
I have a Java NIO channel that is never readable. It does become
writable. I initially register it inside of an event loop as shown
below (I've only included the relevant snippets of code):
SelectionKey NextKey = (SelectionKey) KeyIterator.next();
if (NextKey.isAcceptable()) {
SocketChannel AcceptedChannel = null;
ServerSocketChannel ServerChannel = (ServerSocketChannel)
NextKey.channel();
AcceptedChannel = ServerChannel.accept();
AcceptedChannel.configureBlocking(false);
AcceptedChannel.register(ChannelSelector, SelectionKey.OP_READ |
SelectionKey.OP_WRITE);
and then I test to see if I can read and write:
if (NextKey.isReadable()) {
do fun reading stuff, like reading data from the channel
}
if (NextKey.isWritable()) {
do exciting writing stuff, like writing data to the channel!
}
While I do seem to be able to *write* to the channel, I am completely
unable to read, as the NextKey never becomes readable. I've tried
changing the registration of the channel at various points to read
only or write only, but that doesn't help. What I'm trying to do is
get two clients to talk to each other using NIO. What I have wound up
with is each client yelling at the other, but neither of them
listening to what the other says! What am I doing wrong here? Why
does NextKey never become readable? How can I fix it? I've checked
every Java NIO reference I can find, and nothing helps...
Thanks!