Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connectivity how to ping a website? #334

Closed
EmilAlipiev opened this issue Jun 26, 2018 · 5 comments
Closed

Connectivity how to ping a website? #334

EmilAlipiev opened this issue Jun 26, 2018 · 5 comments

Comments

@EmilAlipiev
Copy link

EmilAlipiev commented Jun 26, 2018

Just switching from connectivity plugin to essentials and it looks like quite differently implemented. i have 2 questions here;

  1. dont we need to check IsSupported like connectivity plugin?
  2. to verify connection, we used to ping a remote page. is it just enough to use code as below? is that even secure for really slowly connections? I would prefer to have a ping option with some timeout.
var current = Connectivity.NetworkAccess;

if (current == NetworkAccess.Internet)
{
    // Connection to internet is available
}

so before it looked like as below

try
           {
               if (!Plugin.Connectivity.CrossConnectivity.IsSupported)
               {
                   IsConnected = true;
                   return true;
               }


               var current = Plugin.Connectivity.CrossConnectivity.Current;
               if (current.IsConnected == false)
               {
                   IsConnected = false;
                   return false;
               }
               else
               {
                   if (await current.IsRemoteReachable("mywebsite.azurewebsites.net") == false)
                   {
                       IsConnected = false;
                       return false;
                   }

               }
           }
           finally
           {
               Plugin.Connectivity.CrossConnectivity.Dispose();
           }
@jamesmontemagno
Copy link
Collaborator

Hey there. Be sure to read the full docs: https://docs.microsoft.com/en-us/xamarin/essentials/connectivity

No need to call IsConnected. If you call it on a platform not supported then it will throw an exception for you to handle.

Correct, Internet is the correct call to check here for NetworkAccess, but the docs highlights more information.

IsReachable was something I wish I never implemented in my original plugin as each device handles this very different and was never 100% reliable. It really makes no sense to try to ping a site to see if it is there instead of just making the web request. You are actually slowing your app down by pinging and then making the request... just make the request :)

@EmilAlipiev
Copy link
Author

@jamesmontemagno thats fair explanation thank you. just one more question please; do we ever have to worry about "Dispose" any of the objects? as you can see above, we disposed things in Connectivity plugin and texttospeech plugin etc. but Essentials doesnt implement disposable.

@jamesmontemagno
Copy link
Collaborator

There is nothing that needs to be disposed at all as we architected each of the APIs to work seamless without having to worry about this.

@danmiser
Copy link

I'd love it if you would revisit adding back IsRemoteReachable. It's been a part of iOS forever. I think Miguel added Reachability code in one of the first samples for MonoTouch.Dialog, if not before. The reachability concept is better for a few reasons, namely:

  • the API call is similar to what is going on with a NetworkService call
  • legacy code (as called out above)
  • it provides a MUCH more accurate answer on if you can actually reach the site vs. that you are theoretically supposed to reach a site (see your comment about connected to a router that doesn't have Internet access, or 1 bar over cellular)

@justinkingst
Copy link

How to ping an IP address in Local Network?
Thank you!

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

No branches or pull requests

4 participants