I have been working on Java NIO communications and reading various writeups regarding this. The document says that I could "or" ops that I am interested in. However, I haven't seen a single example of
channel.register(selector,SelectionKey.OP_ACCEPT|SelectionKey.OP_READ|Selection.OP_WRITE)
Is this a bad idea?
Yep. It's wrong.
ServerSocketChannel.
SocketChannel or a DatagramSocketChannel.
The validOps()
method tells you which operations are valid for a given channel, not that you should need to know at runtime.