Hi
I'm building an iPhoe app with a socket to a PC app , I need to get an image from this PC app.
It's my first time using "CFStreamCreatePairWithSocketToHost".After I establish the socket with "NSOperation" I call
CFStreamClientContext streamContext = {0, self, NULL, NULL, NULL};
BOOL success = CFReadStreamSetClient(myReadStream, kMyNetworkEvents,MyStreamCallBack,&streamContext);
CFReadStreamScheduleWithRunLoop(myReadStream, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
then I call
CFWriteStreamWrite(myWriteStream, &writeBuffer, 3);
// Open read stream.
if (!CFReadStreamOpen(myReadStream)) {
// Notify error
}
.
.
.
while(!cancelled && !finished) {
SInt32 result = CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0.25, NO);
if (result == kCFRunLoopRunStopped || result == kCFRunLoopRunFinished) {
break;
}
if (([NSDate timeIntervalSinceReferenceDate] - _lastRead) MyConnectionTimeout) {
// Call timed out
cancelled = YES;
break;
}
// Also handle stream status
CFStreamStatus status = CFReadStreamGetStatus(myReadStream);
}
and then when I get "kCFStreamEventHasBytesAvailable"
I use
while (CFReadStreamHasBytesAvailable(myReadStream))
{
CFReadStreamRead(myReadStream, readBuffer, 1000);
//and buffer the the bytes
}
It's unpredictable , sometimes I get the whole picture , sometime I got just part of it , and I can't understand what make the different.
can someone has an idea what is wrong here?
thanks