Advertise Books Events Forum News Social Networking Support Us

sdkIQ for iPhone
($4.99)

Shape Up
($0.99)

Your First iPhone App
($1.99)

iVidCam Free
(free)

Kid Art
($0.99)

iPUBQUIZ
(£1.19)

ArtStudio
($3.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 11-29-2009, 11:01 AM   #1 (permalink)
Registered Member
 
Join Date: Jul 2009
Posts: 47
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
Old 11-30-2009, 10:16 AM   #2 (permalink)
Registered Member
 
Jagged's Avatar
 
Join Date: May 2009
Age: 28
Posts: 41
Default

Maybe it works in a new thread
__________________
iPhoneDist.com - distribution service for iPhone applications
Jagged is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Enter the iPhone App Challenge!  Win $500!
» Advertisements
» Stats
Members: 23,855
Threads: 38,628
Posts: 169,579
Top Poster: smasher (2,547)
Welcome to our newest member, laurelbigler58
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 07:06 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0