Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Tutorials > Tutorial Requests

Reply
 
LinkBack Thread Tools Display Modes
Old 10-04-2010, 01:06 AM   #1 (permalink)
Registered Member
 
Join Date: Oct 2010
Posts: 16
pritamsaha is on a distinguished road
Default Synchronous Connection

How do we make synchronous connection?
pritamsaha is offline   Reply With Quote
Old 10-04-2010, 05:31 AM   #2 (permalink)
Registered Member
 
Join Date: Oct 2010
Posts: 16
pritamsaha is on a distinguished road
Default Synchronous connection

Quote:
Originally Posted by pritamsaha View Post
How do we make synchronous connection?
NSString *post = [NSString stringWithFormat:@"req=%@&userid=%@",@"lookandlayo ut",[app.arrUserDetails objectAtIndex:0]];//userid=[app.arrUserDetails objectAtIndex:0]
NSLog(@"PostString=%@",post);
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%d",[postData length]];
NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
[request setURL:[NSURL URLWithString:@"http://test.atvescape.com/forumsettings.php"]];
[request setHTTPMethod:@"POST"];
[request setValueostLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBodyostData];
NSURLConnection *conn=[[[NSURLConnection alloc] initWithRequest:request delegate:self] autorelease];
if(conn)
{
;
}
else
{
;
}
pritamsaha is offline   Reply With Quote
Old 10-04-2010, 05:39 AM   #3 (permalink)
Registered Member
 
Join Date: Oct 2010
Posts: 16
pritamsaha is on a distinguished road
Default Connection deligate

- (void)connection: (NSURLConnection *)connection didReceiveResponse: (NSURLResponse *)response
{
NSLog(@"HERE RESPONSE: %d",[(NSHTTPURLResponse*) response statusCode]);
if(d2)
[d2 release];
d2=[[NSMutableData alloc]init];
}

- (void)connection: (NSURLConnection *)connection didReceiveData: (NSData *)data
{
[d2 appendData: data];

}

- (void)connectionDidFinishLoading: (NSURLConnection *)connection
{
NSString *data_Response = [[NSString alloc] initWithData: d2 encoding:NSUTF8StringEncoding];
NSLog(@"%@",data_Response);
LookAndLayoutParser *parse=[[LookAndLayoutParser alloc]init];
NSError *error;
[parse parseXMLFileAtData: d2 parseError: &error];
[self stopLoading];
[txt removeFromSuperview];
[btn removeFromSuperview];
tab=[[UITableView alloc] initWithFrame: CGRectMake(0,460,320,367) style: UITableViewStylePlain];
tab.delegate = self;
tab.dataSource = self;
tab.autoresizesSubviews = YES;
tab.scrollEnabled = YES;
tab.showsVerticalScrollIndicator=YES;
tab.backgroundColor = [UIColor clearColor];
//tab.separatorColor = [UIColor grayColor];
[self.view addSubview: tab];
[UIView beginAnimations: nil context: nil];
[UIView setAnimationDuration: 0.3];
tab.frame=CGRectMake(0,43,320,367);
[UIView commitAnimations];
}
pritamsaha is offline   Reply With Quote
Old 10-04-2010, 05:41 AM   #4 (permalink)
Registered Member
 
Join Date: Oct 2010
Posts: 16
pritamsaha is on a distinguished road
Default get connection

Quote:
Originally Posted by pritamsaha View Post
How do we make synchronous connection?
NSMutableURLRequest *req = [[[NSMutableURLRequest alloc]init]autorelease];
NSMutableString *str1 = [NSMutableString string];
[str1 appendString:@"http://test.atvescape.com/forum.php?req=getsubforumcategory"];
[str1 appendString:[NSString stringWithFormat:@"&parent=%@",[[app.arrForumCategories objectAtIndex:app.selectedSection] objectAtIndex:0]]];
//[str1 appendString:[NSString stringWithFormat:@"&userid=%@",[app.arrUserDetails objectAtIndex:0]]];

[str1 retain];
NSLog(@"%@",str1);
[req setURL:[NSURL URLWithString:str1]];

NSURLConnection *con =[[[NSURLConnection alloc]initWithRequest:req delegate:self]autorelease];
if(con)
NSLog(@"Connected");
else
NSLog(@"NotConnected");
pritamsaha is offline   Reply With Quote
Old 10-04-2010, 05:45 AM   #5 (permalink)
Registered Member
 
Join Date: Oct 2010
Posts: 16
pritamsaha is on a distinguished road
Default

Quote:
Originally Posted by pritamsaha View Post
How do we make synchronous connection?
NSString *post = [NSString stringWithFormat:@"req=%@&parent=%@&thread=%@",@"r eplies",[[app.arrForumSubCategories objectAtIndex:app.selectedSection] objectAtIndex:0],[[app.arrForumContent objectAtIndex:app.selectedRow]objectAtIndex:3]];//userid=[app.arrUserDetails objectAtIndex:0];
NSLog(@"PostString=%@",post);
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%d",[postData length]];
NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
[request setURL:[NSURL URLWithString:@"http://test.atvescape.com/forum.php"]];
[request setHTTPMethod:@"POST"];
[request setValue: postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody: postData];
NSURLConnection *conn=[[[NSURLConnection alloc] initWithRequest:request delegate:self] autorelease];
if(conn)
{
;
}
else
{
;
}
pritamsaha is offline   Reply With Quote
Old 10-04-2010, 05:56 AM   #6 (permalink)
Registered Member
 
Join Date: Oct 2010
Posts: 16
pritamsaha is on a distinguished road
Default soap connection

Quote:
Originally Posted by pritamsaha View Post
How do we make synchronous connection?

NSMutableString *sRequest = [[NSMutableString string] retain];
NSMutableString *stringPost=[[NSMutableString string] retain];

[stringPost appendString:@"<?xml version=\"1.0\" encoding=\"utf-8\"?>"
"<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"
"<soap:Body>"
"<Signin xmlns=\"http://tempuri.org/\">"
"<card_number>"];
[stringPost appendString:txtfCardNo.text];
[stringPost appendString:@"</card_number>"
"<dob>"];
[stringPost appendString:txtfPrepaidCardId.text];
[stringPost appendString:@"</dob>"
"</Signin>"
"</soap:Body>"
"</soap:Envelope>"];

//NSLog(@"stringPost=%@",stringPost);
[sRequest appendString:stringPost];
//NSLog(@"sRequest=%@",sRequest);

NSURL *myWebserverURL = [NSURL URLWithString:[NSString stringWithFormat:@"%@",@"http://174.136.1.645/dev/testatmsearch/login.php"]];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:myWebserverURL];

// Add the Required values in the header.
[request addValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[request addValue:@"http://tempuri.org/UploadPhoto" forHTTPHeaderField:@"SOAPAction"];
[request addValue:[NSString stringWithFormat:@"%d", [sRequest length]] forHTTPHeaderField:@"Content-Length"];
// Set the action to Post
[request setHTTPMethod:@"POST"];
// Set the body
[request setHTTPBody:[sRequest dataUsingEncoding:NSUTF8StringEncoding]];

// Create the connection
[self performSelector:@selector(showMessage) withObject:nil afterDelay:30.0];
conn=[[[NSURLConnection alloc] initWithRequest:request delegate:self] autorelease];
if(conn)
NSLog(@"Connected");
else
NSLog(@"Not Connected");
pritamsaha is offline   Reply With Quote
Old 10-04-2010, 06:08 AM   #7 (permalink)
Registered Member
 
Join Date: Oct 2010
Posts: 16
pritamsaha is on a distinguished road
Default Asynchronous response

Above all are asynchronous connection

following is the synchronous connection

NSString *urlStr = @"http://192.168.1.250/";
NSString *postBody = @"foo=bar";
NSMutableURLRequest *request;
NSData *postData = [postBody dataUsingEncoding:NSASCIIStringEncoding];
NSError *error;
NSURLResponse *response;
NSHTTPURLResponse *httpResponse;
NSData *dataReply;
id stringReply;

request = [NSMutableURLRequest requestWithURL: [NSURL URLWithString:urlStr]];

[request setHTTPMethod: @"POST"];
[request setHTTPBodyostData];
[request setValue:@"text/xml" forHTTPHeaderField:@"Accept"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];

dataReply = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
stringReply = (NSString *)[[NSString alloc] initWithData:dataReply encoding:NSUTF8StringEncoding];
// Some debug code, etc.
NSLog(@"reply from server: %@", stringReply);
httpResponse = (NSHTTPURLResponse *)response;
status = [httpResponse statusCode];
NSLog(@"HTTP Response Headers %@", [httpResponse allHeaderFields]);
NSLog(@"HTTP Status code: %d", status);
pritamsaha is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 443
17 members and 426 guests
cgokey, dcool, Dj_kades, Droverson, iAppDeveloper, ipodphone, karatebasker, laureix68, LunarMoon, PapaSmurf, patapple, Paul Slocum, peterwilli, pipposanta, QuantumDoja, SLIC, Sloshmonster
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,696
Threads: 94,139
Posts: 402,961
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jasper_muc
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 02:05 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0