jamesmontemagno/ConnectivityPlugin

CrossConnectivity.Current.IsReachable and IsRemoteReachable return false

H4rdC0d3 opened this issue · 13 comments

When I try to ping my local API or any web it always returns false. I have tried with DNS and with IP and it always returns false.

Bug Information

Version Number of Plugin: 3.1.1
Device Tested On: Windows 10 Pro, Galaxy S7 Edge (API 24), Galaxy Tab E (API 19).
Simulator Tested On: N/A.
Version of VS: 15.6.0
Version of Xamarin: 2.5.0.122203
Versions of other things you are using:

Expected Behavior

var reachable = await CrossConnectivity.Current.IsRemoteReachable("google.es"); // return true
var reachable = await CrossConnectivity.Current.IsReachable("http://localhost:3000"); // return true

Actual Behavior

// var reachable = await CrossConnectivity.Current.IsRemoteReachable("google.es"); // return false
var reachable = await CrossConnectivity.Current.IsReachable("http://localhost:3000"); // return false.

Code snippet

// var reachable = await CrossConnectivity.Current.IsRemoteReachable("google.es");
var reachable = await CrossConnectivity.Current.IsReachable("http://localhost:3000"); // or 192.168.1.1:3000
System.Diagnostics.Debug.WriteLine(reachable);

Screenshots

bug

I have the same issue on android 7.0

Me too on Android API 25. Is it because I'm using the emulator?

This logic was re-written in 4.0, please check that.

Im on API 26 android and im suffering the same problem using the latest beta release 4.0.0.186.

I have changed from version 3.1.1 to the latest beta version 4.0.0.186 and I have verified that in Windows 10 the problem has been solved, but in Android API 19 and API 24 it continues with the same problem.

she2 commented

When should we expect a fix for this?

4.0.0.190-beta
Genymotion android simulator
Samsung Galaxy S8 7.0.0 IsReachable return false
Samsung Galaxy S7 8.0.0 IsReachable return true

InetAddress.GetByName(host).IsReachable() is used in the plugin, but this is not a good working...
See https://stackoverflow.com/a/4779436/6499748

Android 5.1 (Samsung J1): works as expected
Android 7.1.1 (HTC One M8): not works as expected

I changed how all of that worked in 4.0.0

Version Number of Plugin: 4.0.0.190-beta
IsReachable Still has issue

Genymotion android simulator
Samsung Galaxy S8 7.0.0 IsReachable return false
Samsung Galaxy S7 8.0.0 IsReachable return true

Real Devices
OPPO R15 - 8.1.0 IsReachable return false
mi5(小米 5) - 8.0.0 IsReachable return false

===================================

I change to use IsRemoteReachable
Task IsRemoteReachable(Uri uri, TimeSpan timeout);

seems result is OK
Genymotion android simulator
Samsung Galaxy S8 7.0.0 IsRemoteReachable return true

Real Devices
OPPO R15 - 8.1.0 IsRemoteReachable return true

It's a few months on, but thought to share for others coming to this even later than me. I had an old Emulator version setup using Android 19, dating from late 2016, which I've continued to use. This returned false on IsRemoteReachable as others have noted above. It also caused other async issues like background async method calls not continuing once a view was changed.

I blew the emulator away and created a new Android 19 emulator (using Visual Studio 15.8.9 and the Android API 28 and Xam.Plugin.Connectivity version 4.0.0.190-beta) and IsRemoteReachable works perfectly. Also the emulators for API 21 and 28 also work fine (and were created recently too). My guess is a bug in the way the emulators functioned, rather than James's excellent code?

Hi James and All,

Thanks for the great Xam.Plugin.Connectivity 4.0.0.190-beta, I can see a lot of work went into this.

Perhaps it's just me, but I'm trying to use the example application: ConnectivitySample without much luck when calling IsReachable(host)
It always returns 'false' for the IOS Simulator and a real iOS Device.

canReach1.Text = await CrossConnectivity.Current.IsReachable(host.Text) ? "Reachable" : "Not reachable";

I've read the ReadMe file several times.

Thanks in advance if anyone has gotten this to work with an example.

Kind regards.

Kevan Evans

@KevanE do you want to share a link to your github repo with a replication?