tags:

views:

112

answers:

0

I'm using a NSInputStream and stream:handleEvent: to receive blocks of data from a socket. Each block of data is the content of a struct.

My problem is that when stream:handleEvent: is invoked, it's possible that not enough data is available to completely fill my struct. It's also possible that many blocks are available but again not enought data to fill the last struct. How should I handle that???

Another thing... Let says that 5 bytes are to be receive. The socket starts receiving the first bytes and stream:handleEvent: is called. You read what is available, let says 4 bytes, and you exit the method. It seems that if the last byte is received after I read the 4 bytes but before I leave the method, stream:handleEvent: won't be invoke again for the 5th byte. How could I know that my last byte is now available?

Thanks for any help!