I want to be able to asynchronously wait on a socket, then synchronously read from it:
for (;;)
{
while (data available on socket)
{
read message from socket;
process it;
}
do something else;
}
I need this because I want to poll a queue with messages from GUI at the same time, so the "do something else" part has a short wait().
Is this possible with Java sockets? I tried to check .available() on a DataInputStreamassociated with the socket, but
- It seems to work only when I connect, not when I accept a connection (???)
- I get no indication that the connection has been closed.
I tried to do it with a Selector, but it requires the socket channel to be in non-blocking mode all the time.