WebClient reliability problems under MonoTouch

Posted by ESCOZ on Wednesday, November 24, 2010

One of the big benefits of MonoTouch is to allow people to use the .NET libraries when developing iPhone apps. Things in general work just great, but it seems I hit a case where this is just not true: network connectivity. The application I developed needed to do very frequent but small calls to a webserver, and over WIFI using the Mono WebClient worked just fine. Unfortunately, when running over 3G or a slow wireless network (wifi over Clear 4G service), about one in every 10 or 15 calls were just failing with a “Could not connect” exception.

After spending hours and hours of investigation and testing, I was able to show that the WebClient and HttpWebRequest classes and the Mono HTTP stack was really at fault. Mono’s framework classes simply aren’t as reliable or as fast as the NSUrlConnection class from Apple. My guess is that Apple’s class put a lot of working writing its framework specifically to run under low-quality wireless networks, like looking at the signal power of the antena and so on, that Mono doesn’t have. Because of that, calls using Mono’s classes were in general 10-20% slower and would fail 5% or so of the time, which was never happening with NSUrlConnection.

It’s hard to demonstrate these problems in a repeatable way, but the difference of using Apple’s framework is visible when compared side to side. I’m not sure what can be done, but I’ll try to work with the MonoTouch guys to see if they can somehow improve the framework.

For now, I have changed most of the applications I have developed to use the NSUrlConnection, using a helper class I’ll post later on.

Update: I posted the helper class on this post.