Re: non blocking write on TCP/IP channel



On 25 juil, 15:39, Lew <l...@xxxxxxxxxxxxxxxx> wrote:
j...@xxxxxxxxxxxxx wrote:
I created a Socket and would like to write data without being
blocked ;
the method setSoTimeout allows to set a timeout for a read call
on the input stream associated with the socket but not for a write
call :
a write call on the output stream will block until the this write is
possible ;
is there a way to have a non blocking write ?

<http://java.sun.com/javase/6/docs/api/java/nio/channels/package-summa...>
and one of the hits from
<http://www.google.com/search?q=Java+NIO+tutorial>
is
<http://www.ibm.com/developerworks/java/edu/j-dw-java-nio-i.html>
and another is
<http://www.ibm.com/developerworks/library/j-perf03174.html>
which covers some of the gotchas (like how to avoid 100% CPU utilization when
doing nothing).

Notice in the code example the important call to:

// Configure the server socket to be non-blocking
// necessary for use with Java's select()
serverChannel.configureBlocking (false);

--
Lew

Hello

I tried this solution which works well ;
I precise that I have to transmit always the same number of bytes N ;
so the size of my buffer is always equal to N ;
the result shows that either N bytes are transmitted or 0 byte ;
0 byte means that the write method fails ; such a failer with
a receiver being busy for too long ; and that's what I expect ;
my problem would be that only n bytes be transmitted (with 0<n<N) ;
if this happens , the receiver would receive an uncomplete
message which would be boring !
is there a way to force the writer to send exactly N bytes ?

thanks

jean-Marie







.



Relevant Pages

  • Re: non blocking write on TCP/IP channel
    ... the method setSoTimeout allows to set a timeout for a read call ... on the input stream associated with the socket but not for a write ...
    (comp.lang.java.help)
  • Re: non blocking write on TCP/IP channel
    ... the method setSoTimeout allows to set a timeout for a read call ... on the input stream associated with the socket but not for a write ...
    (comp.lang.java.help)