This content has been marked as final. Show 6 replies
Well you're doing something wrong. Show us your NIO code.
Thanks for looking into this. I have the exact example code (for NIO) as in the following link.
The code is at the end of the page. I am using the client part of the code.
Thanks for your help.
Not the greatest NIO code. The author seems unaware that closing a channel also cancels all its selection keys so he laboriously programs both operations every time he needs to close the channel. His discussion of OP_CONNECT makes little sense: the important point is that OP_CONNECT is only used in the connection phase and OP_WRITE is only used in the connected phase.
His code registers the channel for OP_WRITE as soon as the connection completes, when there is no pending data to write. This will just cause the selector to spin uselessly doing nothing. The channel should be registered with zero interest-ops and OP_WRITE should be registered when there is something to write, i.e. during the send() operation; and it should be deregistered when the write has completed successfully and there is no more data to write.
Thanks a lot. Do you have any better pointers or examples that explains the NIO operation better.
Appreciate you help.
Thanks a bunch ejp. Will follow the links you have given.