Skip to content
This repository has been archived by the owner on Apr 3, 2023. It is now read-only.

IsRemoteReachable returns true if there is no internet connection #89

Closed
SavikPavel opened this issue Jul 22, 2017 · 8 comments
Closed

Comments

@SavikPavel
Copy link

Bug Information

IsRemoteReachable returns true if you're connected to the WiFi that requires logging in to connect to internet (and you're not logged in).

Version Number of Plugin: 2.3.0
Device Tested On:Samsung Galaxy S7, Android 6.0.1
Simulator Tested On:
Version of VS: XS 6.3
Version of Xamarin: Xamarin.Android 7.3

Steps to reproduce the Behavior

  1. Connect to WiFi that requires logging in to get internet connection.
  2. Don't log in, so you'll have no internet connection.
  3. Try to call CrossConnectivity.Current.IsRemoteReachable("www.google.com");

Expected Behavior

It returns "false" indicating that internet connection is not available.

Actual Behavior

It returns "true" indicating that there is internet connection available (which is not true)

Comments

I've noticed, that you're using await sock.ConnectAsync(sockaddr, msTimeout); to check connection to the remote host. But for such WiFi connections it's really possible to create this connection, though there is no internet connection. Maybe it would be more reliable using Ping for this check?

@jamesmontemagno
Copy link
Owner

Do you still have cell reception though, Android is smart enough to know that in this case that you can still use the cell even when not logged in? What happens when you go to the browser?

@SavikPavel
Copy link
Author

When trying to load "www.google.com" in browser it redirects me to the Login page. By the way, when using Ping.Send it returns "TtlExpired".

@erikpowa
Copy link

erikpowa commented Aug 6, 2017

IsRemoteReachable returns true when google.com is reachable, which is true, but you can't ACCESS it, so the behavior for IsRemoteReachable look fine for me.

@jamesmontemagno
Copy link
Owner

I believe this is as designed. As this is a use case that is nearly impossible to test for.

@SangI762
Copy link

SangI762 commented May 7, 2018

I have similar issue, but I have disconnected ethernet cable from router. Wifi connected, but no internet access.
And if I call IsRemoteReachable() few times (different threads, different methods), one of it returns true. On Android.

@luisguerrerolab
Copy link

luisguerrerolab commented Jun 4, 2018

i'm facing this issue using Xamarin.Forms, currently tested in the Android project.

Steps to reproduce the Behavior

  • Download and compile the Connectivity Plugin source code
  • Create a sample app and delete the Xam.Plugin.Connectivity from the Packages list for both Android and iOS projects
  • Add the references previously generated to both the Android and iOS projects of this sample app
  • In the MainActivity class for the Android project add the following code:
protected override async void OnResume()
{
        base.OnResume();
        await CrossConnectivity.Current.IsRemoteReachable("google.com");
}
  • Turn off the WiFi adapter of the physhical android smartphone and keep mobile data enabled
  • Go to Settings of your mobile carrier app and disable data usage. Confirm that you can't access to any website (it takes forever to load but never actually finish)
  • Add a breakpoint exactly on this code section in the ConnectivityPlugin/src/Connectivity.Plugin.Android/ConnectivityImplementation.cs class:
using (var sock = new Socket())
{
    await sock.ConnectAsync(sockaddr, msTimeout);
    return true;
}

You'll see that the returning value of ConnectAsync() is false, but I'm not sure why is this block set to return true anyway.

@jamesmontemagno
Copy link
Owner

There is really no reason to use these at all. Just call to your API and that will fail if there is an issue. I did re-write all of it in 4.X

@luisguerrerolab
Copy link

I've read the blog post about the changes in version 4, but 😅 I am ashamed to admit that I couldn't find more information on how to get this IsRemoteReachable() function to work, because it is still returning true on version 4 using the scenario mentioned before.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants