Re: NIO
- From: "Remon van Vliet" <remon@xxxxxxxxxxxx>
- Date: Thu, 16 Jun 2005 17:49:37 +0200
"Esmond Pitt" <esmond.nospam.pitt@xxxxxxxxxxxxxxxxxx> wrote in message
news:MIese.18710$F7.16808@xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
> Remon van Vliet wrote:
>
> > Well, this is not how you're supposed to do it. Like you said, the
socket is
> > non-blocking, which means that it will return from your .write() right
away,
> > and after that calls the close(). The proper way to do this is this :
> >
> > 1) establish a connection using a non-blocking socket connect()
> > 2) wait for finishConnect() to return true
>
> This is generally pointless unless you want to timeout the connection
> and are already using select(); usually better to use blocking connect
> with a timeout
True, but if you want full non-blocking connects, this is how to do it. Call
finishConnect as soon as OP_CONNECT has been selected.
>
> > 3) At this point you can send data, do so once the OP_WRITE key is
selected
> > after a select() call
>
> which will happen immediately the connection is complete, not much point
> selecting for it really
It's good practice to do writing once OP_WRITE is selected, that it happens
immediately is true, but doesnt change the fact that it's bad style to
assume it. But fair enough, it will work.
>
> > 4) Write all data (in a secure way, meaning keep track of what you send
and
> > make sure you send it all)
>
> this part is correct, you do need to ensure no short or zero-length
> writes before you close
>
> > 5) Once this is done you can close the connection
>
> and this
.
- Follow-Ups:
- Re: NIO
- From: Bjorn Borud
- Re: NIO
- Prev by Date: Re: JVM vs. EXE comaprison
- Next by Date: Re: Problem with deleteAll() method of Form object. (J2ME)
- Previous by thread: Re: NIO
- Next by thread: Re: NIO
- Index(es):
Relevant Pages
|