ASIHTTPRequest timeout with AnyConnect - ios

In my app I am using ASIHTTPRequest to get information from a server. That works fine as long as I am using the company's wireless.
However, I need to connect now from outside of the network, by using Cisco AnyConnect. On the PC, the connection to the server via VPN works but I cannot reach the server through the app. I always get timeout although I have increased the timeout interval to 60 seconds (which is already too much).
Is there something special that I need to change in the code when I use AnyConnect? Right now, it does not automatically detect the proxy, I get (null) as proxyHost and 0 as proxyPort.

Thank you a lot for the help, #MarkM. Using the IP solved my problem. I just replaced http://<some-words>.local:<port>/<remaining-part-of-url> by http://<IP>:<port>/<remaining-part-of-url> and it works.

Related

Gsm800L gprs disconnect issue

I need to decide which gsm800l module to use for my application. My application is to communicate to a server continuously by sending and receiving a string but needs to run continuously.
As of now I’m using the sim800l module, it works fine and connects to the server but after a couple of minutes it disconnects and probably never connects again I need to manually reset.
How can I resolve this issue?

Http request (GET) timeout sometimes and I want to find the cause

I am developing an iOS app that makes an API request to my server hosted in Heroku.
In my slow internet connection environment, the API request (via Http Get) sometimes results in a timeout. The response time is usually 2000 ms if not timing out.
By "sometimes", I mean about one in 10 requests times out (I do not get any meaningful error code).
I also tested this timeout with 2 devices. When one device is waiting for the server to respond for longer than 2000 ms, I use another device to call the api, to which the server responds normally. But the first device still results in a timeout.
I am not quite sure what is to blame here. My internet connection? My api server on Heroku? I also tested this timeout on Postman and got the same results.
PS. I am based out of Bangkok. The ISP with which I experience the most timeouts is True Broadband.
Any and all advice is appreciated.
Thanks in advance
PPS. In response to comments warning that the question is too broad: Let's ask it this way. If our api calls randomly time out, how can we detect whether it is due to a slow internet connection, or if the fault lies in our own server (or something else)?

Sending SPDY requests results in "The request timed out" errors with NSUrlSession in iOS

My iOS app loads images from an nginx HTTP server. After I send 400+ such requests the networking 'gets stuck' and all subsequent HTTP requests result in "The request timed out" error. I can make the images load again only when I restart the app.
Details:
I am using NSURLSession.sharedSession().dataTaskWithURL to send four hundred HTTP GET requests to jpeg files.
Requests are sent sequentially, one after another. The interval between requests is 10 ms.
Each previous unfinished request is cancelled with cancel() method of NSURLSessionDataTask object.
Interestingly:
I can only have this issue with HTTPS requests and when SPDY is enabled on the server.
Non-secure HTTP requests work fine.
Non-SPDY HTTPS requests work fine. I tested it by turning SPDY off on the server side, in the nginx config.
Problem appears both on iOS 8 and 9, on physical device and in the simulator. Both on Wi-Fi and LTE.
When I look at nginx access logs, I can still see the 'stuck' requests coming in. Important nuance: the request log record appears at the exact moment when the iOS app is giving up on it after the time out period ends.
I was hoping to analyze HTTP requests with Charles Proxy but the problem cures itself when requests go through Charles. That is - everything works with Charles, much like effect in quantum mechanics when the fact of looking influences the outcome.
I was able to reproduce the issue when the iOS app connected to two different servers with vastly different nginx configurations. This probably means that the issue is not related to a particular nginx setup.
I analyzed the app using "Activity Monitor" instrument. The number of threads it is using during the bulk HTTP requests jumps from 5 to 10. In comparison, when I send just a single HTTP requests the number of threads jumps to 8. CPU load rarely goes above 30%.
What can be the cause of the issue? Can anyone recommend other ways or tools for analysing and debugging it?
Analysing with scheduling instrument
Demo app
This demo app reproduces the issue 100% of the time for me.
https://github.com/exchangegroup/ImageLoadDemo
Versions and settings
My nginx config: http://pastebin.com/pYYjdxfP
OS X: 10.10.4 (14E46), iOS: 8 and 9, Xcode: 7.0 (7A218), nginx: 1.9.4
Not ideal workaround
I managed to keep requests working only if I create a new NSURLSession for each individual request and clear the previous session with finishTasksAndInvalidate or invalidateAndCancel.
// Request 1
let configuration = NSURLSessionConfiguration.defaultSessionConfiguration()
let session = NSURLSession(configuration: configuration)
session.dataTaskWithURL ...
// Request 2
// clear the previous request
session.finishTasksAndInvalidate()
let session2 = NSURLSession(configuration: configuration)
session2.dataTaskWithURL ...
One possibility is that iOS started sending the request, and then packet loss prevented the headers and request body from being fully delivered.
Another possibility that comes to mind is that your server may not be logging the request until it actually finishes trying to deliver it, which would make the time stamps in the server logs line up with when the connection was closed, rather than when it was opened. (IIRC, that's what Apache does; I haven't worked with nginx, so I can't speak for its behavior.) If that's the case, then this is just a simple connection stall. As for why it is stalling, I couldn't guess.
Does the problem occur exclusively for HTTPS traffic? If you can reproduce it with HTTP, you don't need Charles Proxy; just use OS X's "Internet Sharing" feature, and capture the packets with tcpdump or wireshark, listening on the bridge interface. If you can't reproduce it with HTTP, my money would be on a problem with fetching the CRLs or performing the OCSP check while validating the server's certificate.
Is your app ending up with a huge number of threads as a result of excessive async dispatching to new queues, by any chance? Because that could easily cause all sorts of odd misbehavior.
How long is the timeout? If it is too short, your app might simply be running up against performance limitations of the hardware while processing the results of 400 requests delivered in only four seconds.
Also, are you trying to schedule these requests simultaneously? Because I seem to recall reading about a bug that causes NSURLSession to hit a brick wall if you start too many tasks in a single session at the same time. You might try adding tasks only after the number of tasks in a session drops below some threshold and see if that fixes the problem.

iOS WiFi probe interval

I am writing an app which connects via WiFi to a proprietary device. The proprietary device acts as a WiFi access point.
When the device powers down, the WiFi connection is terminated, as I would expect.
The iPhone continues to send probe requests, looking for networks to connect to. It follows an exponential backoff algorithm for sending probes.
My problem is that eventually the intervals between the probe requests sent by the iPhone are longer than the timeout on my device, so they don't make a connection.
I am using the Reachability code and it works as I would expect.
It seems that pressing the home button will reset the backoff and send a probe request immediately. Does anyone know of a way to have my app do something similar?
Thanks for any help.
Instead of pinging the internet every time with Reachability, ping a host on the local network like the DNS server or the router (192.168.1.1).
I somehow experienced a similar situation to check if the device was connected in a specific VPN connection. The approach was to ping to a machine in the local network, via standard ping or implementing a ping web service.
If you don't have a backend in your local network then the easiest would be the ping. You can check the following code example from the Apple developer site:
http://developer.apple.com/library/mac/#samplecode/SimplePing/Introduction/Intro.html
I would suspect that if you reconfigure the connection (re-set the WiFi configuration) in your app that the iPhone would restart scanning without the backoff. So your app could keep track of how long it was since the connection was lost and then reconfigure the link after an appropriate amount of time. Possibly you would have to reconfigure to a different SSID and then switch back, depending on how smart the iOS-libraries are.
I'm not shure, if i understand you right. You want to check if the device is still connected to the access point?
I've build an app to connect to a scanner via wifi, the scanner acts as access point. for that i check if the SSID the device is currently connected to is the one of the scanner. to check the CurrentSSID you can use the following code:
+(NSString*)currentSSID {
CFArrayRef myArray = CNCopySupportedInterfaces();
CFDictionaryRef myDict = CNCopyCurrentNetworkInfo(CFArrayGetValueAtIndex(myArray, 0));
if (!myDict) {
return nil;
}
NSDictionary *myDictionary = (__bridge_transfer NSDictionary*)myDict;
return [myDictionary objectForKey:#"SSID"];
}
hope that helps.
I am afraid there is no way of doing so without being rejected during the review (you could read on how to access the SBWifiManager). Apple does not enable any way to access the wifi manager from the sandbox environment. I experienced similar issue connecting my device to various access points (for locating with probe request), up to now with the iOS 7 the probe requests were sent between huge intervals (even 15 min). Try to modify your access points.

How to make iOS believe there is Internet Connectivity

I am working on a web application for iOS that is going to be accesed from a local webserver in a network that has NO internet connectivity at all.
My problem is that everytime an iOS device is locked, it disconnects from the WiFi network, so when the device is unlocked again, it has to reconnect. Part of that reconnection process is determining if there is Internet connection (which there isn't). Until the process is not finished iOS does not allow any DNS resolution (so if I write http://10.0.0.1 it will go there, but not if I request http://something.local.com).
Since we control that network, we want to know how to does iOS verifies Internet connectivity so that we can fake the responses it expects.
I don't know if it's possible to resolve DNS without an internet connection on iOS, but if that's the case, that would be a way better solution since you don't need to mess with your router settings. Use my solution only if it really isn't possible with only code.
I'll suggest you to follow this guide: http://blog.jerodsanto.net/2009/06/sniff-your-iphones-network-traffic to check which actions your iPhone executes to detect an internet connection.
Using this information you could forward the is-there-internet-requests on your router to a local server which fakes the there-is-internet-responses.
This assumes Apple really uses an external server to detect this, which I'm not sure about. But it wouldn't hurt to give it a try!
Have you looked at the Reachability Class? You don't have to use the reachabilityForInternetConnection method, which checks if a default route is available. You can use the reachabilityWithAddress: method and check if your server is reachable.

Resources