• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Connecting streams together
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Connecting streams together


  • Subject: Re: Connecting streams together
  • From: Ken Thomases <email@hidden>
  • Date: Thu, 24 Apr 2008 20:11:10 -0500

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


  • Follow-Ups:
    • Re: Connecting streams together
      • From: vance <email@hidden>
References: 
 >Connecting streams together (From: vance <email@hidden>)

  • Prev by Date: Re: QTMovie grabing while playback
  • Next by Date: Re: QTMovie grabing while playback
  • Previous by thread: Connecting streams together
  • Next by thread: Re: Connecting streams together
  • Index(es):
    • Date
    • Thread