Jun 20, 2008, 02:29 AM
In my iPhone application, i am making use of
NSURLConnection's (id) initWithRequest: (NSURLRequest*)request delegate: (id)delegate three times sequentially to connect to three xml files.
problem is that i am making use of the info from first URL to connect to second URL and info from second URL to connect to thrid and so on..
But as the above method is parsing in thread-model by default, the second connection is tryiong to establish befor the first one get connected...
All three connection are three separate lines in my program...
How to make the first connection to do things before connecting to second?
I mean how to change the thread beahaviour of the above method??
Jun 20, 2008, 10:00 AM
Take a look at NSURLConnection's sendSynchronousRequest method.
Mar 30, 2009, 05:59 AM
we are using NSURLConnection to connect web server using
sendSynchronousRequest method.but We are facing so much problem.
1) Request get blocked / Not responding.
2) how to set
Connect Time out : to use for name resolution.
Send Timeout : to use for sending requests
ReceiveTimeout : time is - receive a response to a request.
NSLog(@"Sending the Load Balence request to server.");
NSString *serverDataString = nil;
NSURL*theServerURL = [NSURL
NSURLConnection *conn = [NSURLConnection
if(conn == nil)
(@"Error",NULL),@"Connection can't establish",NSLocalizedString
serverData = [NSURLConnection
NSLog(@"\n\nERROR code: %d",[myError code]);
NSLog(@"\n\nERROR domain: %@",[myError
code]] strErrorText:[myError localizedDescription]];
dic = [myError userInfo];
arr = [dic allValues];
int i = 0;
for(i = 0 ; i< [arr count]; i++)
NSLog(@"\n%d. %@ \n",i+1,[arr
serverDataString = @"";
serverDataString = [[[NSString alloc]
NSLog(@"Server Response :\n%@
} @catch (id e)
NSLog(@"EXCEPTION: %@ ",e);
In this function we have used api sendSynchronousRequest, Which is
blocking if it don't get response, or in case of heavy load, or if
network connection is not proper.
Mar 30, 2009, 08:02 AM
Don't use sendSynchronousRequest. Use the asynchronous methods instead, which will solve your problems.
The timeout is set in NSURLRequest, but it's not guaranteed to work every time (at least I haven't had that experience). You may need to set a timer to cancel.