Forum Xamarin.Forms

HttpClient very slow

Hello,

I develop an application that displays a MotionJPEG stream.
It was working great until I had a bug on iOS that froze the app when the connexion is lost (code stuck at Stream.ReadAsync and never returns).

So I changed all my streaming code from the old WebRequest - HttpWebRequest - GetRequestStream to the new and recommanded native HttpClient - SendAsync - ReadAsStreamAsync (using AndroidClient and NSUrlSession).

With that change the bug was fixed : great !
But since the streaming is very, very slow...

After some digging, I found that in release on Android it is still ok, but in Debug mode on Android AND on iOS (Debug and Release), it is very very slow.
It looks like the code is running fast (as usual), but the app has too few to read from the stream (like a bad slow internet connexion).

I've tried several things without success...
Do you have any ideas please ?

Thanks.
Nicolas.

Posts

  • AndreiMisiukevich_AndreiMisiukevich_ USMember ✭✭✭✭✭

    Hi
    try with this pack https://www.nuget.org/packages/Ideine.ModernHttpClient/

    var httpClient = new HttpClient(new NativeMessageHandler());

  • kisscoool18kisscoool18 Member ✭✭

    Hi,
    I've seen this package but it looks like is old and abandoned...
    https://github.com/paulcbetts/ModernHttpClient/issues/255

    I'm more looking for a futur-proof solution :)
    Thanks

  • AndreiMisiukevich_AndreiMisiukevich_ USMember ✭✭✭✭✭
  • kisscoool18kisscoool18 Member ✭✭

    Oh I see, there is a forked, more recent one, I'll definitely try that, thanks.
    Any idea of the supposed advantages of this library regarding the Native HttpClient offered by Xamarin that use AndroidClient and NSUrlSession ?
    Thanks :)

  • Milner99Milner99 Member ✭✭

    I have a similar issue @kisscoool18 - did you find success with this ModernHttpClient?

    My scenario is a call to a https web server for an RSS feed. iOS is ok. Mac OSX is ok (using postman) - both fast. Android intermittently VERY slow, 60+ seconds for a request!

    Tried WebClient, HttpWebRequest, HttpClient all of which make no difference to the requests, no consistency. Tried with Proxy = null. In Android Build properties I have HttpClient Implementation "AndroidClientHandler" and SSL/TLS implementation "Native TLS 1.2+.

    Weirdly I use a HttpClient to another server and all requests are quick, never an issue. Seems just this one particular web server that's causing me a headache - but only an Android (simulator and device)

    Any thoughts?

  • kisscoool18kisscoool18 Member ✭✭

    I'm sorry @Milner99 but I've dropped Xamarin 2 years ago, in favor of Flutter. And I'll never coming back.
    Good luck ;)

  • Milner99Milner99 Member ✭✭

    Thanks for the heads up.

    To add to this strange slow network issue is the follow.

    • Using a HttpClient and 3/4G connection I can get the data (xml) back quick, sub 3 seconds for around 400KB. Fine.
    • Using a HttpClient and WiFi I am seeing consistent load times of 30-60+ seconds and many times no data back at all...

    To confirm this is android device only (V9 or v10)

    Explain that!? (anyone!) (please!)

Sign In or Register to comment.