0

According to https://docs.oracle.com/javase/7/docs/api/java/nio/channels/SelectionKey.html#OP_READ

Suppose that a selection key's interest set contains OP_READ at the start of a selection operation. If the selector detects that the corresponding channel is ready for reading, has reached end-of-stream, has been remotely shut down for further reading, or has an error pending, then it will add OP_READ to the key's ready-operation set and add the key to its selected-key set.

What is the condition for a SocketChannel to be ready for reading?

How to explicitly make it ready for reading?

Thanks!!!

user207421
  • 305,947
  • 44
  • 307
  • 483
Ertai Duo
  • 11
  • 3

1 Answers1

0

What is the condition for a SocketChannel to be ready for reading?

Data is present in the socket receive buffer, or the peer has closed or shutdown its end of the connection, or an error is pending.

How to explicitly make it ready for reading?

From the peer, send something, or close the connection, o shut it down for output. From this end, you can't, except to shut it down for input, which will deliver end of stream on the next read, which you probably don't want.

user207421
  • 305,947
  • 44
  • 307
  • 483