Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7929825
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T20:12:58+00:00 2026-06-03T20:12:58+00:00

I use SimpleFTPSample to do a ftp request for listing the derictory info. Part

  • 0

I use “SimpleFTPSample” to do a ftp request for listing the derictory info. Part of the code is as below:

- (void)_startReceive
{
 ......
    self.networkStream = (NSInputStream *) ftpStream;
    self.networkStream.delegate = self;
    [self.networkStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];

    [NSTimer scheduledTimerWithTimeInterval:TIMEOUTFTP target:self
                                   selector:@selector(dealTimeOut:) userInfo:nil repeats:NO];
 ......
}

I also set a NSTimer to stop the networkStream after TIMEOUTFTP, the networkStream will also be closed if the request is finished correctly within TIMEOUTFTP that I define. I use the method in another place like this:

- (void)downLoadData
{
    NSArray* receivedData;
    [ftpService _startReceive];

   //wait until the network is closed
    while (ftpService.isReceiving) {}

    receivedData = ftpService.dataArray;

    if([receivedData count] == 0) {
       NSLog(@"no data get");   
    }
    else {
       NSLog(@"get data number %d", [receivedData count]);
    }

}

The situation is that the program stuck at “while (ftpService.isReceiving) {}”. I am not familiar with Multiple Thread. May be I do not understand the run loop correctly. Can someone tell me why this happen and how to achieve my purpose?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T20:13:00+00:00Added an answer on June 3, 2026 at 8:13 pm

    You should reconsider whether you really want to wait for the received data before letting the program proceed. Instead, you should put your UI into a state where it shows that it’s downloading and restricts what the user can do, return control to the app’s main event loop, and let it call your delegate method when data is received. Only once the data is received should you unlock the UI and proceed to the next step, whatever that is.

    Blocking the main thread of the app will result in poor user experience and may get your app terminated.

    If you really want to do this, though, you need to run the run loop rather than doing a busy wait. Something like:

    while (ftpService.isReceiving)
        [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];
    

    Actually, in this case where you’re running the run loop yourself, you should use a different run loop mode both here and where you schedule the stream. The default run loop mode will contain run loop sources from the rest of the frameworks and it’s dangerous to let those fire from an inner run loop of your own. Just use an arbitrary string that’s likely to be unique to your program for the mode.

    A run loop is a collection of various sources of events and inputs (and timers). Both your code and various parts of the frameworks will schedule sources in the run loop. They depend on the run loop being run in order to receive the events/inputs/timer-fires and handle them. By not running the run loop and just busy-waiting, you were preventing the stream from receiving data from the FTP connection and handling it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Use case example: Client A comes to request sales information, enters their zip code
Use case: class MyTask(Task): queue = 'default_queue' def run(self): # do work Normally I
I use Qt 4.4.2 in Visual Studio 2008. When I am writing code, IntelliSense
use case is simple: I want to run some boiler plate code before each
use this code, in the Preferences activity, to know when the reset preference has
Use case: user clicks the link on a webpage - boom! load of files
use LWP::Simple; use Parallel::ForkManager; @links=( [http://prdownloads.sourceforge.net/sweethome3d/SweetHome3D-2.1-windows.exe,SweetHome3D-2.1-windows.exe], [http://prdownloads.sourceforge.net/sweethome3d/SweetHome3D-2.1-macosx.dmg,SweetHome3D-2.1-macosx.dmg], [http://prdownloads.sourceforge.net/sweethome3d/SweetHome3DViewer-2.1.zip,SweetHome3DViewer-2.1.zip], ); # Max 30 processes for
use this website a lot but first time posting. My program creates a number
Use case: I've just entered insert mode, and typed some text. Now I want
use Rack::Static, :urls => ['/stylesheets', '/images'], :root => 'public' run proc { |env| [200,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.