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?
c# xamarin xamarin.forms xamarin.android
add a comment |
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?
c# xamarin xamarin.forms xamarin.android
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
add a comment |
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?
c# xamarin xamarin.forms xamarin.android
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
c# xamarin xamarin.forms xamarin.android
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
add a comment |
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
add a comment |
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;
}
}
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
add a comment |
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.
add a comment |
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
add a comment |
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;
}
}
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
add a comment |
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;
}
}
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
add a comment |
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;
}
}
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;
}
}
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
add a comment |
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
add a comment |
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.
add a comment |
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.
add a comment |
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.
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.
answered Nov 8 at 10:53
TaiT's
1,009515
1,009515
add a comment |
add a comment |
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
add a comment |
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
add a comment |
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
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
answered Nov 8 at 11:00
Tiago dias
318
318
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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