Waiting for response takes about 300ms , so i can send only 3-4 requests per second to my custom device, its to slow, i'm working on improving the speed of "user interaction".
Now i'm using this code:
NSURLRequest* request = [NSURLRequest requestWithURL:[NSURL URLWithString:url] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:0.5];
NSHTTPURLResponse* response = nil;
NSError* error = nil;
[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
You could fire requests asynchronously properly implementing + (void)sendAsynchronousRequest:(NSURLRequest *)request queue:(NSOperationQueue *)queue completionHandler:(void (^)(NSURLResponse*, NSData*, NSError*))handler
Let's say you wan't to fire a set of requests every 5 seconds. You can implement a repeating timer that issues first request. You could make request delegates issue requests in sequencial order (each delegate issues the next request). In very simplified meta language it would look like:
- repeatingTimer5sHandler {
issue1stRequestWithHandler:handlerFor1stRequest;
}
- handlerFor1stRequest {
handle response
issue2ndRequestWithHandler:handlerFor2ndRequest;
}
- handlerFor2ndRequest {
handle response
issue3rdRequestWithHandler:handlerFor3rdRequest;
}
- handlerFor3rdRequest {
handle response
issue4thRequestWithHandler:handlerFor4thdRequest;
}
- handlerFor4thRequest {
handle response
}
At the bottom of this page is a working solution. It's only for one request but it should get you started.