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 (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to