You’re doing something wrong then. NSStreams are just raw streams of bytes; they don’t do any kind of encoding or serialization framing or conversion at all. They’re exactly the same abstraction as found in most other platforms (java.io.Stream, FILE*, Unix file handles, etc.)
Just a guess, but: One common newbie mistake people make with streams is thinking that if you write data in blocks of specific sizes, then on the other end of the stream your read calls will get blocks of the same sizes. For example if you first write 100 bytes, then write 25000 bytes, then write 8000 bytes; sometimes people think that the first read call will get 100 bytes, the second read call will get 25000, and the third read call will get 8000. This isn’t true. The stream is just an undifferentiated series of bytes, and the number of bytes you get on any specific read call is based only on things like the way the stream is transmitted (e.g. in network packets) and the sizes of the buffers on either end.
Have you looked at Apple’s sample code for networking? The PictureSharing example shows how to send and receive images between computers; that seems very similar to what you’re doing.
—Jens |