开发者

Having time out problem at time sync the data on the server from iPhone

I am trying to sync the data from iPhone to server but didn't get it. I was doing this before in the last four days but not getting any success now. It shows

  1. ** that Connection failed! Error - The request timed out. http://192.168.0.68:91/JMAPI?RequestType=User&Command=NEW
  2. ** -[NSConcreteMutableData release]: message sent to deallocated instance 0x165590a0

My server is create with help of C# And I have the local server link like this http://192.168.0.68:91/JMAPI For posting the data I code like this

    -(void)sendRequest

    {

        NSDate* date = [NSDate date];
        //Create the dateformatter object
        NSDateFormatter* formatter = [[[NSDateFormatter alloc] init] autorelease];
        //Set the required date format
        [formatter setDateFormat:@"yyyy-MM-dd HH:MM:SS"];
        //Get the string date
        NSString* str = [formatter stringFromDate:date];

        NSString *post = [NSString stringWithFormat:@"Token=%@&JourneyID=%@&JourneyName=%@&Locationname=%@&StartDate=%@&Distance=%@&ShareType=%@&LastSyncDate=%@",tokenapi,Journey_ID,Journey_Name,Location_Name,Start_Date,Dist,Share_type,str];
        NSLog(@"%@",post);
        NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES]; 
        NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]]; 
        NSLog(@"%@",postLength);
        NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init]autorelease]; 
        [request setURL:[NSURL URLWithString:@"http://192.168.0.68:91/JMAPI?RequestType=User&Command=NEW"]]; 
        [request setHTTPMethod:@"POST"]; 
        [request setValue:postLength forHTTPHeaderField:@"Content-Length"]; 
        [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"]; 
        [request setHTTPBody:postData];

        NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self];

        if (theConnection) {
            webData = [[NSMutableData data] retain];
            NSLog(@"%@",webData);

        }

    }
/// this for checking is that Sync is work or not 

-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response 
{   
    [webData setLength: 0]; 
} 

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

} 

-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error 
{     
    [connection release];  
    [webData r开发者_C百科elease]; 
    NSLog(@"Connection failed! Error - %@ %@",
          [error localizedDescription],
          [[error userInfo] objectForKey:NSURLErrorFailingURLStringErrorKey]);
***//ABove line i am getting error that Connection failed! Error - The request timed out.
    http://192.168.0.68:91/JMAPI?RequestType=User&Command=NEW*** 

} 

-(void)connectionDidFinishLoading:(NSURLConnection *)connection 
{      
    NSString *loginStatus = [[NSString alloc] initWithBytes: [webData mutableBytes] length:[webData length] encoding:NSUTF8StringEncoding]; 
    NSLog(@"%@",loginStatus);  
    [loginStatus release];           
    [connection release];  
    [webData release]; 
} 


And i am getting this data from sqlitedatabase and from here i am calling the -(void)sendRequest Which is containing   posting method . For code like this 

    -(void)information
    {
        NSString *filePath = [self getWritableDBPath];

        sqlite3 *database;
        if(sqlite3_open([filePath UTF8String], &database) == SQLITE_OK)
        {
            NSString *qu = @"Select  JourneyID,JourneyName,Locationname,StartDate,Distance,ShareType FROM UserJourney where SyncStatus ='1'";
            sqlite3_stmt *compiledStatement;
            if(sqlite3_prepare_v2(database, [qu UTF8String], -1, &compiledStatement, NULL) == SQLITE_OK) 
            {



                while(sqlite3_step(compiledStatement) == SQLITE_ROW ) 
                {

                    char *firstColumn = (char *)sqlite3_column_text(compiledStatement, 0);
                    Journey_ID= [[NSString alloc]initWithUTF8String:firstColumn];
                    NSLog(@"%@",Journey_ID);
                    char * scondColumn = (char *)sqlite3_column_text(compiledStatement, 1);
                    Journey_Name = [[NSString alloc]initWithUTF8String:scondColumn];
                    NSLog(@"%@",Journey_Name);
                    char *thridColumn = (char *)sqlite3_column_text(compiledStatement, 2);
                    Location_Name =[[NSString alloc]initWithUTF8String:thridColumn];
                    NSLog(@"%@",Location_Name);
                    char *fuothColumn = (char *)sqlite3_column_text(compiledStatement, 3);
                    Start_Date = [[NSString alloc]initWithUTF8String:fuothColumn];
                    NSLog(@"%@",Start_Date);
                    Dist = [NSNumber numberWithFloat:(float)sqlite3_column_double(compiledStatement, 4)];
                    NSLog(@"%f",Dist);
                    Share_type = [NSNumber numberWithInt:(int)sqlite3_column_int(compiledStatement, 5)];
                    NSLog(@"%f",Share_type);
                    NSLog(@"%@,%@,%@,%@,%@",Journey_ID,Journey_Name,Location_Name,Start_Date,Dist,Share_type);

    [self sendRequest];***// this is place from where I call the posting method(sendRequest)***

    }
        }
        sqlite3_finalize(compiledStatement);
    }
    sqlite3_close(database);
}

I hope get help soon Thank you


There's two questions here.

(1) Timeout - looks like you're not connecting with whatever is at 192.168.9.68:91 - @Mahesh's comment is right; check it in Safari in the simulators browser to check that you can connect to that machine.

(2) This is the more serious one.

You are calling [self sendRequest] for each row in your sqlite result set. However, all your requets are sharing the same webData object :(

You need to make a seperate class that contains sendRequest and webData and make an instance of it for each request you want to send.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜