Writing To NSStream Relying on hasSpaceAvailable method or Delegate Event NSStreamEventHasSpaceAvailable

StackOverflow https://stackoverflow.com/questions/21476878

While writing onto NSStream Should i Rely on

'hasSpaceAvailable' method or the event in the 'handle:event' method

'NSStreamEventHasSpaceAvailable'

Or Should i check 'hasSpaceAvailable' if not available, i have to retry after a particular amount of time or should i wait till the delegate event to call till i begin to write?

As of now its working when i use hasSpaceAvailable and retry after some time dont know if its the right practice.

Any Help would be of much great.

有帮助吗?

解决方案

When you're about to send first piece of data use hasSpaceAvailable to determine whether stream is ready.

After sending some data you'll be getting stream:handleEvent: method called and there you should check if NSStreamEvent var is equal to NSStreamEventHasSpaceAvailable; then you can write more data to the stream, otherwise something is wrong or stream is full.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top