Shri
Shri

Reputation: 2139

how to call NSStream Synchronously

How to call NSStream synchronously to get the results??

Presently I am getting a async call back in one of its delegate methods

 `(void)stream:(NSStream *)theStream handleEvent:(NSStreamEvent)streamEvent`- 

Upvotes: 4

Views: 1925

Answers (1)

Mr. Berna
Mr. Berna

Reputation: 10655

An NSStream is an abstract class that neither reads or writes data to a stream. To actually access the data you'll need a concrete subclass such as NSInputStream or NSOutputStream (or your custom subclass of NSStream). To read the data in an NSInputStream call read:maxLength:. You'll probably want to poll the stream, asking it if any new data is available, with hasBytesAvailable. An NSOutputStream has analogous write:maxLength: and hasSpaceAvailable methods.

You are highly encouraged by the iOS documentation to avoid polling, and use run-loop scheduling instead by responding to the async call back delegate methods.

Upvotes: 7

Related Questions