Currently I'm working on a Java NIO Server (single-threaded) and have encountered some problems. The server accepts incoming connections, writes initial packets (the packet contains some data that client uses for further communication) to clients but doesn't read from them. The server tries to read only when I close the client and, of course, it returns -1.
When accepting connection, it's being registered under:
selectionKey = socketChannel.register(_selector, SelectionKey.OP_READ)
selectionKey.isReadable()
returns false
(should it?)
Before sending initial packet, ops are changed to:
_selectionKey.interestOps(_selectionKey.interestOps() | SelectionKey.OP_WRITE)
After sending initial packet, ops are changed to:
selectedKey.interestOps(selectedKey.interestOps() & ~SelectionKey.OP_WRITE)
Packet gets sent.
What could be the problem? Can it be related to client?