Re: NIO
- From: Esmond Pitt <esmond.nospam.pitt@xxxxxxxxxxxxxxxxxx>
- Date: Thu, 16 Jun 2005 12:59:24 GMT
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
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
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: Remon van Vliet
- Re: NIO
- Prev by Date: Re: Disconnect causing READ_OP?
- Next by Date: Re: NIO
- Previous by thread: Re: NIO
- Next by thread: Re: NIO
- Index(es):
Relevant Pages
|