Re: Connecting streams together
Re: Connecting streams together
- Subject: Re: Connecting streams together
- From: vance <email@hidden>
- Date: Thu, 24 Apr 2008 18:25:34 -0700
Thank you for the reply, I did a sample that sets up the stream in
that fashion up to a degree.
So there should be 2 instances, right? One instance for the
NSInputStream and one instance for the NSOutputStream
OR
Should there be just ONE instance and then we cast it to NSInputStream
or NSOutputStream depending on what interface is required at that time?
Regards,
Vance
On Apr 24, 2008, at 6:11 PM, Ken Thomases wrote:
On Apr 24, 2008, at 7:15 PM, vance wrote:
Is there a way to connect an NSOutputStream and NSInputStream
together with in-memory buffer?
So while the Input Stream is getting filled, the Output stream
starts pulling the data out.
The context of the problem is streaming. The generator creates the
sounds samples, and puts them to an NSInputStream instance. Then
the server needs to empty that stream out and send them over the
wire.
I tried to connect the two (NSInputStream and NSOutputStream) using
a shared NSMutableData instance passed to both using initWithData
and initToBuffer but it does not work.
Is anyone familiar on how to connect stream instances together so
that the data can just flow through them?
I don't think there's any automatic way. You have to do some work,
but I think it's a small amount of work.
You would set a delegate on the input stream, and schedule the
stream on a run loop. Then, you run the run loop (if it's your main
event loop, then it runs automatically). When your delegate gets
the stream:handleEvent: message, and when that message indicates
that there's data available, you read the data and write it to the
output stream.
As noted in the Stream Programming Guide, you're not guaranteed that
the read will be non-blocking, even if you've been told there's data
available. So, you might want to do this on a background thread and
run your own run loop.
-Ken
_______________________________________________
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