DatagramChannel & NIO Selector
- I'm using DatagramChannel and Selector.
DatagramChannel channel = DatagramChannel.open();
channel.connect(new InetSocketAddress(127.0.0.1, 9010));
- I have registered this DatagramChannel to SelectionKey.OP_READ.
1. My problem is that when I'm checking the selector with selectedKeys() i'm getting that the key is isReadable, but with 0 bytes received.
Why I'm getting 0 bytes ? (there is no other application / other side which send me messages)
2. It seem that if I will check when when I will get some bytes (> 0) I will loop over and over ... , no ? (seem bad performance)