i have a problem with channels. i wrote a little chat server& client. the first message is received and multicasted to every client - works fine.
the simplified code is:
while (isRunning())
{
SocketChannel ch = null;
try
{
int selected = selector.select();
if (selected==0)
{
continue;
}
Iterator<SelectionKey> selectedKeys = selector.selectedKeys().iterator();
while (selectedKeys.hasNext())
{
SelectionKey key = selectedKeys.next();
ch = (SocketChannel) key.channel();
bytes = readAll(ch)
}
} // end method run
readAll reads as much bytes as possible, then returns the bytes or null. if it returns a byte[], the data is complete. in the other case, it will continue reading from the bytebuffer the next time select() returns. (it’s managing everything perfectly, the problem is definetly not inside this method)
my problem begins when i try to send a second message. select() returns immediately - forever. and gives me an empty set.
wtf is going on ?
accoding to the api, this is not possible.