1

I'm currently doing a FTP client for my project. I've scheduled the readstream/writeStream with the runloop to read the file from the harddisk/write the file to the harddisk and send it to the server. After uploading and downloading the file I unschedule the stream from the runloop. This works fine for the first time I send the file. The second time when i try to send the file. Streams are getting created and scheduled with the run loop. But run loop doesnt fire. I don know. Can anyone please help me out

Below are the codes that I used to schedule and unschedule

For uploading

readStream=CFReadStreamCreateWithFile(kCFAllocatorDefault, fileURL);
writeStream=CFWriteStreamCreateWithFTPURL(kCFAllocatorDefault,(CFURLRef ) ftpURL);
BOOL readStreamOpened=CFReadStreamOpen(readStream);
BOOL clientCallBackSet=CFWriteStreamSetClient(writeStream, kNetworkEvents, MyUploadCallBack, &callBackContext);

CFWriteStreamScheduleWithRunLoop(writeStream, CFRunLoopGetCurrent(), kCFRunLoopCommonModes);
CFReadStreamUnscheduleFromRunLoop(syncStructure->readStream, CFRunLoopGetCurrent(), kCFRunLoopCommonModes);

Downloading:

readStream=CFReadStreamCreateWithFTPURL(kCFAllocatorDefault,(CFURLRef)ftpURL);
writeStream=CFWriteStreamCreateWithFile(kCFAllocatorDefault,fileURL);
Boolean writeStreamOpened=CFWriteStreamOpen(writeStream);
BOOL status= CFReadStreamSetClient(readStream, kNetworkEvents,MyDownloadCallBack,& callBackContext);
CFReadStreamScheduleWithRunLoop(readStream, CFRunLoopGetCurrent(), kCFRunLoopCommonModes);
CFWriteStreamUnscheduleFromRunLoop(syncStructure->writeStream, CFRunLoopGetCurrent(), kCFRunLoopCommonModes);

Can anyone please help me. I`m cracking my head for 2 days.

Alfonso
  • 8,386
  • 1
  • 43
  • 63
sivakumar
  • 21
  • 4
  • Are you running this on a separate thread? If so, do you run the runloop after you setup the streams? – Alfonso Jun 17 '11 at 06:32
  • No I was running this on the main thread. I know that I should have provide the run method for the runloop by providing with control statements. But I cannot give run command for the mainthread runloop. Is there any solution? – sivakumar Jun 18 '11 at 19:13

1 Answers1

0

After a couple of days, I solved the problem. I checked the code using the method of polling mentioned in the reference guide. When I did that I noticed the problem was with the timeout setting in my ftp server. After the servers time out, It didnt accept any connection hence my runloop was waiting to call the callback function

sivakumar
  • 21
  • 4