Verify not only internet connection but if it is passing data - XAMARIN











up vote
0
down vote

favorite












I'm having a problem with this verification of the internet connection. See I have this verification in my code:



  if (CrossConnectivity.Current.IsConnected)
{
...
}


It works, but I think there is a situation that this do not cover, I have a shopping right next door to my office, I enter the shopping and the device just connects with the shopping WI-FI, but it's not passing data, because it need's to login in the session to get free WI-FI from the shopping.



So my question in resume is, is there a way, not only to verify if the device is conected to the internet, but if it is passing data through the connection?










share|improve this question




















  • 2




    jamesmontemagno.github.io/ConnectivityPlugin/PingaHost.html Perhaps each time after the connection changes, you can ping, say google.com, and see if theres a response. Although make sure your userbase isn't in China, where Google is blocked haha.
    – sme
    Nov 8 at 10:50












  • @sme "Although make sure your userbase isn't in China, where Google is blocked haha" good one.
    – Dbl
    Nov 8 at 10:55










  • @Dbl Yeah, its true though haha.. maybe ping bing.com instead.
    – sme
    Nov 8 at 11:11















up vote
0
down vote

favorite












I'm having a problem with this verification of the internet connection. See I have this verification in my code:



  if (CrossConnectivity.Current.IsConnected)
{
...
}


It works, but I think there is a situation that this do not cover, I have a shopping right next door to my office, I enter the shopping and the device just connects with the shopping WI-FI, but it's not passing data, because it need's to login in the session to get free WI-FI from the shopping.



So my question in resume is, is there a way, not only to verify if the device is conected to the internet, but if it is passing data through the connection?










share|improve this question




















  • 2




    jamesmontemagno.github.io/ConnectivityPlugin/PingaHost.html Perhaps each time after the connection changes, you can ping, say google.com, and see if theres a response. Although make sure your userbase isn't in China, where Google is blocked haha.
    – sme
    Nov 8 at 10:50












  • @sme "Although make sure your userbase isn't in China, where Google is blocked haha" good one.
    – Dbl
    Nov 8 at 10:55










  • @Dbl Yeah, its true though haha.. maybe ping bing.com instead.
    – sme
    Nov 8 at 11:11













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I'm having a problem with this verification of the internet connection. See I have this verification in my code:



  if (CrossConnectivity.Current.IsConnected)
{
...
}


It works, but I think there is a situation that this do not cover, I have a shopping right next door to my office, I enter the shopping and the device just connects with the shopping WI-FI, but it's not passing data, because it need's to login in the session to get free WI-FI from the shopping.



So my question in resume is, is there a way, not only to verify if the device is conected to the internet, but if it is passing data through the connection?










share|improve this question















I'm having a problem with this verification of the internet connection. See I have this verification in my code:



  if (CrossConnectivity.Current.IsConnected)
{
...
}


It works, but I think there is a situation that this do not cover, I have a shopping right next door to my office, I enter the shopping and the device just connects with the shopping WI-FI, but it's not passing data, because it need's to login in the session to get free WI-FI from the shopping.



So my question in resume is, is there a way, not only to verify if the device is conected to the internet, but if it is passing data through the connection?







c# xamarin xamarin.forms xamarin.android






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 8 at 12:28









ΩmegaMan

15.7k44160




15.7k44160










asked Nov 8 at 10:40









Tiago dias

318




318








  • 2




    jamesmontemagno.github.io/ConnectivityPlugin/PingaHost.html Perhaps each time after the connection changes, you can ping, say google.com, and see if theres a response. Although make sure your userbase isn't in China, where Google is blocked haha.
    – sme
    Nov 8 at 10:50












  • @sme "Although make sure your userbase isn't in China, where Google is blocked haha" good one.
    – Dbl
    Nov 8 at 10:55










  • @Dbl Yeah, its true though haha.. maybe ping bing.com instead.
    – sme
    Nov 8 at 11:11














  • 2




    jamesmontemagno.github.io/ConnectivityPlugin/PingaHost.html Perhaps each time after the connection changes, you can ping, say google.com, and see if theres a response. Although make sure your userbase isn't in China, where Google is blocked haha.
    – sme
    Nov 8 at 10:50












  • @sme "Although make sure your userbase isn't in China, where Google is blocked haha" good one.
    – Dbl
    Nov 8 at 10:55










  • @Dbl Yeah, its true though haha.. maybe ping bing.com instead.
    – sme
    Nov 8 at 11:11








2




2




jamesmontemagno.github.io/ConnectivityPlugin/PingaHost.html Perhaps each time after the connection changes, you can ping, say google.com, and see if theres a response. Although make sure your userbase isn't in China, where Google is blocked haha.
– sme
Nov 8 at 10:50






jamesmontemagno.github.io/ConnectivityPlugin/PingaHost.html Perhaps each time after the connection changes, you can ping, say google.com, and see if theres a response. Although make sure your userbase isn't in China, where Google is blocked haha.
– sme
Nov 8 at 10:50














@sme "Although make sure your userbase isn't in China, where Google is blocked haha" good one.
– Dbl
Nov 8 at 10:55




@sme "Although make sure your userbase isn't in China, where Google is blocked haha" good one.
– Dbl
Nov 8 at 10:55












@Dbl Yeah, its true though haha.. maybe ping bing.com instead.
– sme
Nov 8 at 11:11




@Dbl Yeah, its true though haha.. maybe ping bing.com instead.
– sme
Nov 8 at 11:11












3 Answers
3






active

oldest

votes

















up vote
1
down vote













I didn't try this solution but it might help you.



if (CrossConnectivity.Current.IsConnected)
{
if (ConnectGoogle())
{
return true;
}
else
{
//
}
}


ConnectGoogle method



public bool ConnectGoogle()
{
try
{
HttpURLConnection urlc = (HttpURLConnection)(new URL("http://www.google.com").OpenConnection());
urlc.SetRequestProperty("User-Agent", "Test");
urlc.SetRequestProperty("Connection", "close");
urlc.ConnectTimeout = 10000;
urlc.Connect();
return (urlc.ResponseCode == HttpStatus.Accepted);
}
catch (Exception ex)
{
//Log(ex.Message);
return false;
}
}





share|improve this answer

















  • 1




    FYI: One of the issues of using a hostname is a captured portal typically redirects all DNS requests to the portal until you are logged/accepted the TOS/...
    – SushiHangover
    Nov 8 at 10:57


















up vote
1
down vote













You could use System.Net.WebClient and test open/read an url. Also another way could be to ping a resource that is theoritically never offline. i.e. google.



Something like:



if (CrossConnectivity.Current.IsConnected)
{
try {
Ping ping = new Ping();
String host = "google.com";
byte buffer = new byte[32];
int timeout = 1000;
PingOptions pingOptions = new PingOptions();
PingReply reply = ping.Send(host, timeout, buffer, pingOptions);
if (reply.Status == IPStatus.Success){
// Your code here...
}
}
catch (Exception) {
return false;
}
}


Hope it helps.






share|improve this answer




























    up vote
    0
    down vote













    Thanks everyone, I see all answers work in my situation, but I used this method from https://jamesmontemagno.github.io/ConnectivityPlugin/PingaHost.html, you could open it or just see it down here:



     var verificaPassagemDados = await CrossConnectivity.Current.IsRemoteReachable("google.com");


    Thanks @sme






    share|improve this answer





















      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














       

      draft saved


      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53206009%2fverify-not-only-internet-connection-but-if-it-is-passing-data-xamarin%23new-answer', 'question_page');
      }
      );

      Post as a guest
































      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      1
      down vote













      I didn't try this solution but it might help you.



      if (CrossConnectivity.Current.IsConnected)
      {
      if (ConnectGoogle())
      {
      return true;
      }
      else
      {
      //
      }
      }


      ConnectGoogle method



      public bool ConnectGoogle()
      {
      try
      {
      HttpURLConnection urlc = (HttpURLConnection)(new URL("http://www.google.com").OpenConnection());
      urlc.SetRequestProperty("User-Agent", "Test");
      urlc.SetRequestProperty("Connection", "close");
      urlc.ConnectTimeout = 10000;
      urlc.Connect();
      return (urlc.ResponseCode == HttpStatus.Accepted);
      }
      catch (Exception ex)
      {
      //Log(ex.Message);
      return false;
      }
      }





      share|improve this answer

















      • 1




        FYI: One of the issues of using a hostname is a captured portal typically redirects all DNS requests to the portal until you are logged/accepted the TOS/...
        – SushiHangover
        Nov 8 at 10:57















      up vote
      1
      down vote













      I didn't try this solution but it might help you.



      if (CrossConnectivity.Current.IsConnected)
      {
      if (ConnectGoogle())
      {
      return true;
      }
      else
      {
      //
      }
      }


      ConnectGoogle method



      public bool ConnectGoogle()
      {
      try
      {
      HttpURLConnection urlc = (HttpURLConnection)(new URL("http://www.google.com").OpenConnection());
      urlc.SetRequestProperty("User-Agent", "Test");
      urlc.SetRequestProperty("Connection", "close");
      urlc.ConnectTimeout = 10000;
      urlc.Connect();
      return (urlc.ResponseCode == HttpStatus.Accepted);
      }
      catch (Exception ex)
      {
      //Log(ex.Message);
      return false;
      }
      }





      share|improve this answer

















      • 1




        FYI: One of the issues of using a hostname is a captured portal typically redirects all DNS requests to the portal until you are logged/accepted the TOS/...
        – SushiHangover
        Nov 8 at 10:57













      up vote
      1
      down vote










      up vote
      1
      down vote









      I didn't try this solution but it might help you.



      if (CrossConnectivity.Current.IsConnected)
      {
      if (ConnectGoogle())
      {
      return true;
      }
      else
      {
      //
      }
      }


      ConnectGoogle method



      public bool ConnectGoogle()
      {
      try
      {
      HttpURLConnection urlc = (HttpURLConnection)(new URL("http://www.google.com").OpenConnection());
      urlc.SetRequestProperty("User-Agent", "Test");
      urlc.SetRequestProperty("Connection", "close");
      urlc.ConnectTimeout = 10000;
      urlc.Connect();
      return (urlc.ResponseCode == HttpStatus.Accepted);
      }
      catch (Exception ex)
      {
      //Log(ex.Message);
      return false;
      }
      }





      share|improve this answer












      I didn't try this solution but it might help you.



      if (CrossConnectivity.Current.IsConnected)
      {
      if (ConnectGoogle())
      {
      return true;
      }
      else
      {
      //
      }
      }


      ConnectGoogle method



      public bool ConnectGoogle()
      {
      try
      {
      HttpURLConnection urlc = (HttpURLConnection)(new URL("http://www.google.com").OpenConnection());
      urlc.SetRequestProperty("User-Agent", "Test");
      urlc.SetRequestProperty("Connection", "close");
      urlc.ConnectTimeout = 10000;
      urlc.Connect();
      return (urlc.ResponseCode == HttpStatus.Accepted);
      }
      catch (Exception ex)
      {
      //Log(ex.Message);
      return false;
      }
      }






      share|improve this answer












      share|improve this answer



      share|improve this answer










      answered Nov 8 at 10:50









      CGPA6.4

      2,1331729




      2,1331729








      • 1




        FYI: One of the issues of using a hostname is a captured portal typically redirects all DNS requests to the portal until you are logged/accepted the TOS/...
        – SushiHangover
        Nov 8 at 10:57














      • 1




        FYI: One of the issues of using a hostname is a captured portal typically redirects all DNS requests to the portal until you are logged/accepted the TOS/...
        – SushiHangover
        Nov 8 at 10:57








      1




      1




      FYI: One of the issues of using a hostname is a captured portal typically redirects all DNS requests to the portal until you are logged/accepted the TOS/...
      – SushiHangover
      Nov 8 at 10:57




      FYI: One of the issues of using a hostname is a captured portal typically redirects all DNS requests to the portal until you are logged/accepted the TOS/...
      – SushiHangover
      Nov 8 at 10:57












      up vote
      1
      down vote













      You could use System.Net.WebClient and test open/read an url. Also another way could be to ping a resource that is theoritically never offline. i.e. google.



      Something like:



      if (CrossConnectivity.Current.IsConnected)
      {
      try {
      Ping ping = new Ping();
      String host = "google.com";
      byte buffer = new byte[32];
      int timeout = 1000;
      PingOptions pingOptions = new PingOptions();
      PingReply reply = ping.Send(host, timeout, buffer, pingOptions);
      if (reply.Status == IPStatus.Success){
      // Your code here...
      }
      }
      catch (Exception) {
      return false;
      }
      }


      Hope it helps.






      share|improve this answer

























        up vote
        1
        down vote













        You could use System.Net.WebClient and test open/read an url. Also another way could be to ping a resource that is theoritically never offline. i.e. google.



        Something like:



        if (CrossConnectivity.Current.IsConnected)
        {
        try {
        Ping ping = new Ping();
        String host = "google.com";
        byte buffer = new byte[32];
        int timeout = 1000;
        PingOptions pingOptions = new PingOptions();
        PingReply reply = ping.Send(host, timeout, buffer, pingOptions);
        if (reply.Status == IPStatus.Success){
        // Your code here...
        }
        }
        catch (Exception) {
        return false;
        }
        }


        Hope it helps.






        share|improve this answer























          up vote
          1
          down vote










          up vote
          1
          down vote









          You could use System.Net.WebClient and test open/read an url. Also another way could be to ping a resource that is theoritically never offline. i.e. google.



          Something like:



          if (CrossConnectivity.Current.IsConnected)
          {
          try {
          Ping ping = new Ping();
          String host = "google.com";
          byte buffer = new byte[32];
          int timeout = 1000;
          PingOptions pingOptions = new PingOptions();
          PingReply reply = ping.Send(host, timeout, buffer, pingOptions);
          if (reply.Status == IPStatus.Success){
          // Your code here...
          }
          }
          catch (Exception) {
          return false;
          }
          }


          Hope it helps.






          share|improve this answer












          You could use System.Net.WebClient and test open/read an url. Also another way could be to ping a resource that is theoritically never offline. i.e. google.



          Something like:



          if (CrossConnectivity.Current.IsConnected)
          {
          try {
          Ping ping = new Ping();
          String host = "google.com";
          byte buffer = new byte[32];
          int timeout = 1000;
          PingOptions pingOptions = new PingOptions();
          PingReply reply = ping.Send(host, timeout, buffer, pingOptions);
          if (reply.Status == IPStatus.Success){
          // Your code here...
          }
          }
          catch (Exception) {
          return false;
          }
          }


          Hope it helps.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 8 at 10:53









          TaiT's

          1,009515




          1,009515






















              up vote
              0
              down vote













              Thanks everyone, I see all answers work in my situation, but I used this method from https://jamesmontemagno.github.io/ConnectivityPlugin/PingaHost.html, you could open it or just see it down here:



               var verificaPassagemDados = await CrossConnectivity.Current.IsRemoteReachable("google.com");


              Thanks @sme






              share|improve this answer

























                up vote
                0
                down vote













                Thanks everyone, I see all answers work in my situation, but I used this method from https://jamesmontemagno.github.io/ConnectivityPlugin/PingaHost.html, you could open it or just see it down here:



                 var verificaPassagemDados = await CrossConnectivity.Current.IsRemoteReachable("google.com");


                Thanks @sme






                share|improve this answer























                  up vote
                  0
                  down vote










                  up vote
                  0
                  down vote









                  Thanks everyone, I see all answers work in my situation, but I used this method from https://jamesmontemagno.github.io/ConnectivityPlugin/PingaHost.html, you could open it or just see it down here:



                   var verificaPassagemDados = await CrossConnectivity.Current.IsRemoteReachable("google.com");


                  Thanks @sme






                  share|improve this answer












                  Thanks everyone, I see all answers work in my situation, but I used this method from https://jamesmontemagno.github.io/ConnectivityPlugin/PingaHost.html, you could open it or just see it down here:



                   var verificaPassagemDados = await CrossConnectivity.Current.IsRemoteReachable("google.com");


                  Thanks @sme







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 8 at 11:00









                  Tiago dias

                  318




                  318






























                       

                      draft saved


                      draft discarded



















































                       


                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53206009%2fverify-not-only-internet-connection-but-if-it-is-passing-data-xamarin%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest




















































































                      Popular posts from this blog

                      Schultheiß

                      Verwaltungsgliederung Dänemarks

                      Liste der Kulturdenkmale in Wilsdruff