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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T00:38:18+00:00 2026-05-23T00:38:18+00:00

I have an application that uses an API to get real time updates on

  • 0

I have an application that uses an API to get real time updates on the website. They use what they call a long-polling technique:

Long polling is a variation of the
traditional polling technique and
allows emulation of an information
push from a server to a client. With
long polling, the client requests
information from the server in a
similar way to a normal poll. However,
if the server does not have any
information available for the client,
instead of sending an empty response,
the server holds the request and waits
for some information to be available.
Once the information becomes available
(or after a suitable timeout), a
complete response is sent to the
client. The client will normally then
immediately re-request information
from the server, so that the server
will almost always have an available
waiting request that it can use to
deliver data in response to an event.
In a web/AJAX context, long polling is
also known as Comet programming.

Long polling is itself not a push
technology, but can be used under
circumstances where a real push is not
possible.

Basically this enforces to make a request back to the server once you’ve got a response back. What is the best way to do this in an iphone application? This eventually has to run in the background.

  • 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-05-23T00:38:19+00:00Added an answer on May 23, 2026 at 12:38 am

    This is exactly the sort of use-case that NSURLConnection sendSynchronousRequest is perfect for:

    - (void) longPoll {
        //create an autorelease pool for the thread
        NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
    
        //compose the request
        NSError* error = nil;
        NSURLResponse* response = nil;
        NSURL* requestUrl = [NSURL URLWithString:@"http://www.mysite.com/pollUrl"];
        NSURLRequest* request = [NSURLRequest requestWithURL:requestUrl];
    
        //send the request (will block until a response comes back)
        NSData* responseData = [NSURLConnection sendSynchronousRequest:request
                                returningResponse:&response error:&error];
    
        //pass the response on to the handler (can also check for errors here, if you want)
        [self performSelectorOnMainThread:@selector(dataReceived:) 
              withObject:responseData waitUntilDone:YES];
    
        //clear the pool 
        [pool drain];
    
        //send the next poll request
        [self performSelectorInBackground:@selector(longPoll) withObject: nil];
    }
    
    - (void) startPoll {
        //not covered in this example:  stopping the poll or ensuring that only 1 poll is active at any given time
        [self performSelectorInBackground:@selector(longPoll) withObject: nil];
    }
    
    - (void) dataReceived: (NSData*) theData {
        //process the response here
    }
    

    Alternately, you could use async I/O and delegate callbacks to accomplish the same thing, but that would really be kind of silly in this case.

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

Sidebar

Related Questions

I have an application that uses the old REST API call Friends.getAppUsers to get
I have a .NET application that uses some API calls, for example GetPrivateProfileString .
I have a C++ application that uses the Win32 API for Windows, and I'm
I have an application that uses the Google Maps API to geocode distances between
I have a small application that uses the same API as the powerscript examples
I am developing RESTful API for my application. All getters (that use HTTP GET)
I have an application that uses WebSphere MQ Java API along with a configuration
I am developing sample application that uses Google Map API. I have generated Google
I have an application that uses NHibernate as its ORM and sometimes it experiences
I have client application that uses WCF service to insert some data to backend

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.