This content has been marked as final. Show 4 replies
Write returns zero when your socket's send buffer fills up. That in turn happens when the receiver's socket receive buffer fills up, and that in turn happens when the read is slow reading. Not much you can do about that except wait. That's what OP_WRITE is for. When you get the zero, register OP_WRITE instead of OP_READ and return to the select loop; when you get the OP_WRITE event, try the write again; if it succeeds, switch back to OP_READ.
can you provide me a sample code for this situation.
because i read from one channel when the read option is fired, and i get the data, and i write that in other channel that connects with the client outside.
so, i have a handler and another handler as attachement one of the other, it is like a cross action.
I've practically provided you with pseudo-code. That's usually as far as I go for nothing. Writing the code is your job. The Internet is full of examples. Try for instance the very long thread here called 'Taming the NIO Circus', although you can ignore most of it except the contributions by pkwooster and myself.
thank you ejp, after reading the full article, i could get my app working without loosing packages
what i did was,
i added a linked list to have a queue of messages , and when the loop checks that i have a signal for writing, then i check if the buffer has remaining bytes to be written,
if it does i write the bytes, if still are remaining bytes then i register the signal for writing again for the next loop,
in the other hand i take the first message from the linkedlist and i write the bytes and the thing loops in the same thing.
thank you very much.