Re: Flushing NSOutputStream gotten from NSNetService
Re: Flushing NSOutputStream gotten from NSNetService
- Subject: Re: Flushing NSOutputStream gotten from NSNetService
- From: Jens Alfke <email@hidden>
- Date: Fri, 2 Jul 2010 10:43:27 -0700
On Jul 2, 2010, at 5:36 AM, Alexander Spohr wrote:
> I have some streams gotten from NSNetServices getInputStream:outputStream:. I send very small chunks (from 1 to 1000 bytes) of data through them. I would like to flush the stream after I wrote a chunk to get the data immediately sent to the other side.
> Is that possible or does the NSOutputStream flush after every write:maxLength: anyway?
TCP has some finely-tuned algorithms to decide when to send the buffer. Usually it’s best not to second-guess these, but there are some cases where you do need to. Terminal protocols like telnet and ssh use setsockopt to set a special immediate mode (I can’t remember the name of the option but it’s in the man page.).
I’m not sure how you get from an NSStream object to the underlying socket descriptor that you’d pass to setsockopt. You can get to that from a CFStream, but I don’t know whether NSStream is toll-free-bridged to CFStream.
(And there’s no reason you have to use NSStream with Bonjour. The -getInputStream:outputStream: method is just a convenience — you can resolve the service to find its IP address and then use whatever API you like to open a socket.)
—Jens_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden