I like the detachNewThreadSelector ... approach, but FYI you can use NSOperation and NSOperationQueue . It will throw noncompetitive operations on separate threads.
To get streams, you look at things like this:
[self.outputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:mode];
Definitely look at Apple's “PictureSharing” sample at http://developer.apple.com/library/mac/#samplecode/PictureSharing .
In particular, copy the FileSendOperation and FileReceiveOperation and QRunLoopOperation . I also use the LinkedImageFetcher sample QWatchedOperationQueue , which works well with the PictureSharing classes. I took the classes * SendOperation and * ReceiveOperation and turned them into classes sending / receiving what I need (some NSData).
Then it is as simple as:
FileSendOperation *op; op = [[[FileSendOperation alloc] initWithFilePath:somePath outputStream:outStream ] autorelease]; [self.queue addOperation:op finishedAction:@selector(networkingDone:)];
source share