Re: non blocking write on TCP/IP channel
- From: jmc@xxxxxxxxxxxxx
- Date: Tue, 31 Jul 2007 05:57:45 -0700
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
.
- References:
- non blocking write on TCP/IP channel
- From: jmc
- Re: non blocking write on TCP/IP channel
- From: Lew
- non blocking write on TCP/IP channel
- Prev by Date: XMPP Java bot loop question
- Next by Date: Re: XMPP Java bot loop question
- Previous by thread: Re: non blocking write on TCP/IP channel
- Next by thread: @override?
- Index(es):
Relevant Pages
|