NIO only sends data one way

(Imagine a really big post here, explaining how I could only get a channel that sent data one way. Then imagine me kicking myself as I realised my mistake while typing the last sentance.)

So instead I’ll just ask- why do we need to use a selector to write to a channel? Whats wrong with just calling channel.write(byteBuffer) and letting it get on with it? BlahBlah’s tutorial on the wiki just mentions that you need to use the selector to tell it to ‘send more data’. Doesn’t it have an internal buffer anyway?

heh

Don’t sweat it. We have a term for that in my old group at Sun. We called it the “cardboard programmer.” Sometimes you just need someone to stand there like a cut out while you explain the problem and the answer drops right out :slight_smile:

I’m not sure that I understand your question correctly, but if you’re asking why a Selector is nescessary to do non-blocking writes ala a normal Socket OutputStream, I’d say it’s because no matter how large the internal buffer is and how fast the underlying network link is, you can always fill the buffers if you want. Therefore, the Selector is there to notify you when the buffers/network can take more data. Furthermore, Selectors are crucial when dealing with thousands of sockets in a scalable way.

  • elias