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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T07:45:12+00:00 2026-05-12T07:45:12+00:00

I want to make two separate asynchronous internet lookups. However, they are stepping on

  • 0

I want to make two separate asynchronous internet lookups. However, they are stepping on each other and I’m not sure why.

When I dig around, it appears the two lookups are both operating on the same object (symptom: the second call is resetting “thisPage” set by the first call).

Maybe this has something to do with delegate usage (still not comfortable in this area)?


I’ve created a class CSNet and I initialize it:

CSNet               *startupPage;
CSNet               *positionUpdatePage;
startupPage = [[CSNet alloc] init];
positionUpdatePage = [[CSNet alloc] init];

Later, I try to use each object:

[startupPage getPage:self page:pageName];

and:

[positionUpdatePage getPage:self page:pageName];

module-level variable:

enum pageType {nothing, startup, positionUpdate, acquireOpponents, fire, changeCredentials};
enum pageType thisPage;

getPage call:

-(void)getPage:(id)delegate page:(NSString *)page {
m_Delegate = delegate;
if ([[page substringToIndex:2] isEqual:@"st"]) {
        thisPage = startup;
} else {
    if ([[page substringToIndex:2] isEqual:@"pu"]) {
        thisPage = positionUpdate;
    } else {
        if ([[page substringToIndex:2] isEqual:@"ao"]) {
            thisPage = acquireOpponents;
        } else {
            if ([[page substringToIndex:2] isEqual:@"fi"]) {
                thisPage = fire;
            } else {
                if ([[page substringToIndex:2] isEqual:@"cc"]) {
                    thisPage = changeCredentials;
                }   
            }
        }
    }
}   

NSURLRequest *startupRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:[
    [NSString stringWithFormat: @"%@%@", SERVER, page] 
    stringByReplacingOccurrencesOfString:@" " withString:@"%20"]]];
startupConnection = [[NSURLConnection alloc] initWithRequest:startupRequest delegate:self];

if(startupConnection)
{
    workInProgress = YES;
    m_RequestData = [[NSMutableData data] retain];
}
 }

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{

// this method is called when the server has determined that it
// has enough information to create the NSURLResponse
// it can be called multiple times, for example in the case of a
// redirect, so each time we reset the data.
// receivedData is declared as a method instance elsewhere
[m_RequestData setLength:0];

}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data 
{
// append the new data to the receivedData
// receivedData is declared as a method instance elsewhere
[m_RequestData appendData:data];    
}

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
// release the data object
[m_RequestData release];

// inform the user
NSLog(@"Connection failed! Error - %@ %@", [error localizedDescription], [[error userInfo] objectForKey:NSErrorFailingURLStringKey]);
workInProgress = NO;
}

returning back to delegate:

 - (void)connectionDidFinishLoading:(NSURLConnection *)connection {
if(workInProgress == YES) {
    workInProgress = NO;
    switch (thisPage) {
        case startup:
            //if ([m_Delegate respondsToSelector:@selector(startupReady:)])
                [m_Delegate startupReady:m_RequestData];
            break;
        case positionUpdate:
            //if ([m_Delegate respondsToSelector:@selector(positionUpdateReady:)])
                [m_Delegate positionUpdateReady:m_RequestData];
            break;
        case acquireOpponents:
            //if ([m_Delegate respondsToSelector:@selector(opponentsReady:)])
                [m_Delegate opponentsReady:m_RequestData];
            break;
        case fire:
            //if ([m_Delegate respondsToSelector:@selector(fireReady:)])
                [m_Delegate fireReady:m_RequestData];
            break;
        case changeCredentials:
            //if ([m_Delegate respondsToSelector:@selector(changeCredentialsReady:)])
                [m_Delegate changeCredentialsReady:m_RequestData];
            break;
        default:
            break;
    }
    [m_RequestData release];
}   
}
  • 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-12T07:45:12+00:00Added an answer on May 12, 2026 at 7:45 am

    You said thisPage is a module-level variable. I assume that means that it’s not an instance variable. If this is the case, there’s only one thisPage variable shared between all instances of CSNet. Naturally, if you have two of them running at once, they’ll clobber each other.

    If you really want each instance of CSNet to have its own thisPage variable, then make it an instance variable.

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

Sidebar

Related Questions

I have two DateTime objects: StartDate and EndDate . I want to make sure
I want to make a table that simply has two integer columns to serve
Let's make this very easy. What I want: @array = qw/one two one/; my
I want to make sure people can't type the name of a PHP script
I want to make sure that a set of functions have the same signature
I want to make two different headers for my WordPress project, so the frontpage
I want to make a composition with two objects. I can do it with
I want to make an etag that matches what Apache produces. How does apache
I want to make a table in SqlServer that will add, on insert, a
I want to make a copy of an ActiveRecord object, changing a single field

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.