Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

View Single Post
Old 11-29-2009, 12:01 PM   #1 (permalink)
J0ker
Registered Member
 
Join Date: Jul 2009
Posts: 59
Default NSstream reading\writing

Hi!

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:
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
J0ker is offline   Reply With Quote
 

» Advertisements
» Stats
Members: 158,870
Threads: 89,225
Posts: 380,694
Top Poster: BrianSlick (7,129)
Welcome to our newest member, triclopus
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 06:45 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.