Hi, in an iPhone app, I have a socket connection through wifi, and I need to read from inputStream and write to outputStream. The problem is that stream management is event-driven, and I have to wait for event NSStreamEventHasBytesAvailable before reading. So I can't know when reading\writing outside the handleEvent:eventCode delegate method.
I tried a while loop, but I realized that during the while loop the app doesn't receive delegate messages and never stops:
Pseudo-code:
-(void) myFunction {
canRead=NO;
[self writeToStream:someData];
while(!canRead) { };
readData=[self readFromStream];
}
- (void)stream:(NSStream *)stream handleEvent:(NSStreamEvent)eventCode {
switch(eventCode) {
case NSStreamEventHasBytesAvailable: {
canRead=YES;
break;
}
}
}
I think I could read\write inside the delegate method, but I need to read\write many times outside that.
Help! Thankyou