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.