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 8445997
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T09:48:33+00:00 2026-06-10T09:48:33+00:00

I am interacting with a web-controlled hardware device. You send it a request via

  • 0

I am interacting with a web-controlled hardware device. You send it a request via a URL (e.g., http://device/on?port=1 or http://device/off?port=3) to turn stuff on and off, and it sends back “success” or “failure”. It is a simple device, however, so while it’s processing a request — i.e., until it returns the status of the request that it’s processing — it will ignore all subsequent requests. It does not queue them up; they just get lost.

So I need to send serial, synchronous requests. I.e., req#1, wait for response#1, req#2, wait for response#2, req#3, wait for response #3, etc.

Do I need to manage my own thread-safe queue of requests, have the UI thread push requests into one end of the queue, and have another thread pull the requests off, one at a time, as soon as the previous one either completes or times out, and send the results back to the UI thread? Or am I missing something in the API that already does this?

Thanks!

…R

  • 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-10T09:48:35+00:00Added an answer on June 10, 2026 at 9:48 am

    What should work is to use an NSOperationQueue instance, and a number of NSOperation instances that perform the various URL requests.

    First, set up a queue in the class that will be enqueueing the requests. Make sure to keep a strong reference to it, i.e.

    @interface MyEnqueingClass ()
    
    @property (nonatomic, strong) NSOperationQueue *operationQueue;
    
    @end
    

    Somewhere in the implementation, say the init method:

        _operationQueue = [[NSOperationQueue alloc] init];
        _operationQueue.maxConcurrentOperationCount = 1;
    

    You want basically a serial queue, hence the maxConcurrentOperationCount of 1.

    After setting this up, you’ll want to write some code like this:

    [self.operationQueue addOperationWithBlock:^{
        NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"my://URLString"]];
        NSError *error;
        NSURLResponse *response;
        NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
        if (!responseData)
        {
            //Maybe try this request again instead of completely restarting? Depends on your application.
            [[NSOperationQueue mainQueue] addOperationWithBlock:^{
                //Do something here to handle the error - maybe you need to cancel all the enqueued operations and start again?
                [self.operationQueue cancelAllOperations];
                [self startOver];
            }];
        }
        else
        {
            //Handle the success case;
        }
    }];
    
    [self.operationQueue addOperationWithBlock:^{
        //Make another request, according to the next instuctions?
    }];
    

    In this way you send synchronous NSURLRequests and can handle the error conditions, including by bailing out completely and starting all over (the lines with -cancelAllOperations called). These requests will be executed one after the other.

    You can also of course write custom NSOperation subclasses and enqueuing instances of those rather than using blocks, if that serves you.

    Hope this helps, let me know if you have any questions!

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

Sidebar

Related Questions

Basically my app is interacting with a web service that sends back a weird
I am interacting with a web server using a desktop client program in C#
I am using a WCF Service (which is a web role) and is interacting
I've read through all of the Spring 3 Web docs: http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/spring-web.html but have been
I have a slight situation. I'm interacting with a web service using RestSharp, where
I am in Web Service Environment and I am interacting with Google API for
I have an interactive web application powered by jQuery where users can manipulate visual
For creating interactive web apps, Silverlight and Jquery (jqueryUI included) are used. Is there
I have an issue using xsd dataTime with regard to integrating a web client
I am modeling my web app interaction using the Page Object pattern. Most pages

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.