Java.NIO channel never becomes writable

  • Thread starter nooneinparticular314159
  • Start date
N

nooneinparticular314159

I'm using Java.NIO to implement a connection between two nodes. The
local node appears to connect ok to the remote node, and successfully
creates a channel. But the channel ever becomes writable, so no
communication ever occurs. What could be causing this?

Thanks!
 
C

Christian

I'm using Java.NIO to implement a connection between two nodes. The
local node appears to connect ok to the remote node, and successfully
creates a channel. But the channel ever becomes writable, so no
communication ever occurs. What could be causing this?

Thanks!

Can you show us a bit of your code? (ssce)

Otherwise it would be just guessing..
First mistakes that comes to my mind would be that you never set the key
to be intrested in write operation.
 
N

nooneinparticular314159

Can you show us a bit of your code? (ssce)

Otherwise it would be just guessing..
First mistakes that comes to my mind would be that you never set the key
to be intrested in write operation.

I think that was it. After I sent the key to writable, problem
solved. :)

What is ssce?

Thanks!
 
N

nooneinparticular314159

I think that was it.  After I sent the key to writable, problem
solved.  :)

What is ssce?

Thanks!

Ok. I was wrong. That doesn't seem to solve it. I clearly have two
nodes writing to teh channel, but the channel never contains a
readable key, even if it is set to readable, or to readable and
writable.

I check for it with:
if (NextKey.isReadable()) {

but it never is.

I also check for if (NextKey.isWritable()) {
and it often is. In fact, if I don't make the channels read only when
I don't have soemthing to write, they never stop being writable and my
program just loops on them.

Thanks!
 
G

Gordon Beaton

On Sun, 16 Mar 2008 18:04:25 -0700 (PDT),
In fact, if I don't make the channels read only when I don't have
soemthing to write, they never stop being writable and my program
just loops on them.

That's normal. And it's why you shouldn't check for writable (even
when writing) except when the previous write() came up short.

Search for "nio writeable" in this group to find many discussions
about this behaviour.

/gordon

--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,776
Messages
2,569,602
Members
45,184
Latest member
ZNOChrista

Latest Threads

Top