|
I thought only non-programmer check google to test their internet connection
Even I, sometimes open google to check internet cnnection,
But on the other hand, what should one code to test their internet connection....
|
|
|
|
|
Well, in a client-server application you should know the address of the server, so I'd say that's the address you need to ping, or better yet, make a socket connection to the server port.
Even if it's only SQL, if you can connect to port 433 (in most cases), you probably have connectivity. Some servers may block ICMP requests, so that's never a good option.
|
|
|
|
|
How do you differentiate between "Our server has gone boom, hoepfully our internal monitoring app has paged a sysadmin to fix it." and "Your Internet connection is busted; yell at your ISP." Testing several major internet sites is really the only way to go there since I've encountered more than a few cases where something in my/my isps networking gear went splat and Windows never got a clue.
Did you ever see history portrayed as an old man with a wise brow and pulseless heart, waging all things in the balance of reason?
Is not rather the genius of history like an eternal, imploring maiden, full of fire, with a burning heart and flaming soul, humanly warm and humanly beautiful?
--Zachris Topelius
Training a telescope on one’s own belly button will only reveal lint. You like that? You go right on staring at it. I prefer looking at galaxies.
-- Sarah Hoyt
|
|
|
|
|
|
internetgetconnectedstate has always worked for me. You still have to check the availability of the resource.
"Go forth into the source" - Neal Morse
|
|
|
|
|
Someone I know *cough* *cough* once used that approach. They pinged a machine in the building. If the response was successful, the UI for the application was, ahem, altered in a particular way. A checkbox that represented a spectacularly stupid idea was renamed to "Steve mode", where the aforementioned 'Steve' created the idea.
Software Zen: delete this;
|
|
|
|
|
A reverse easter egg.. I love it
We can program with only 1's, but if all you've got are zeros, you've got nothing.
|
|
|
|
|
Sometimes you have network but not internet.
The better way to test it, is to use a well know network host or IP.
If you only want to check if you have network connection and it is good, check for a host like Google is the better choice.
Or, you can check for a Registrar, like 'registro.br' here in Brazil.
But I rely more on Google than an Registrar, 'cause I never saw and never heard someone speaking that Google was down.
|
|
|
|
|
A LAN in the same building is not the internet. Works as intended 
modified 20-Oct-19 21:02pm.
|
|
|
|
|
If the only solution is to check for a web, check for internic.net if internic.net fails then it is as good as the end of the (internet) world.
I have made a web search to the subject and there are examples taking the same approach you describe. Sure there are APIs to test for network connection.
Then again what exactly do we call Internet? (in particular with ACTA around the corner). It may be better idea to identify the ISP server address and check for that, then again there is the risk of a broken suboceanic cable or a satelite failure... although I understand that USA will probably not notice that, I'm not in USA. You could check for some national, institutional .gov website, until it got attacked with denial of service.
By the way, will that software work properly in china or under other government firewall that decides that google is no good? Allow be to doubt it (there is always the risk that another party will use that name, and "poison" the DNS... may be on government's behalf).
Talking about DNS, you could have a host files, or local DNS server that says that google is localhost, and the same goes for internic.net. Which is good, because you may want to mock Internet for testing (and survive the so claimed Maya's predictions).
The best solution is not to test for Internet, but test for what you need on Internet, for example microsoft products will check for microsoft.com, not because their developers think microsoft.com is the Internet, but because it is the part of the Internet they need to work. For the case of P2P or similar solutions don't even test, let the connection fail.
|
|
|
|
|
I seem to recall a Google blog post (though I can't find it again) that said they leave themselves open to ICMP on purpose specifically so that people can use them to test Internet Access.
Also, Microsoft uses a similar idea for the Network Connectivity Icon in Windows. See http://blog.superuser.com/2011/05/16/windows-7-network-awareness/[^]
I don't know exactly what URL Apple uses but my iPod touch does the same thing.
|
|
|
|
|
Thank you, you answered some remaining questions I still had on the topic.
|
|
|
|
|
|
I just got this from someone else's project:
internal static bool IsInternetConnected(string webSite)
{
bool flag;
string str;
try
{
if (webSite == null)
{
str = "www.google.com";
}
else
{
str = webSite;
}
webSite = str;
Dns.GetHostEntry(webSite);
flag = true;
}
catch
{
flag = false;
}
return flag;
}
I think a little more than DNS is required to check internet connectivity.
|
|
|
|
|
I have to say that just checking for one web address is pretty poor!
In order to determine if an internet end point is available, check to see if the connection is there (via Ping, or what ever) and this if the timeout (only needs to be short) fails, then try the next node that will serve the desired result. once you have run out of nodes to check then you are offline. You may wish to try again later...
There may be blips at an endpoint caused by many events (power outage, load balancers, etc) which could (and do) lead to momentary drop outs. It is just that most browsers have quite a good timeout that they "just work" and the end user notices only a slightly slower page load than some drastic moment at a data centre!
But then I could be wrong!
|
|
|
|
|
Ladies and Gentlemen!
Direct, from the wonders of Q&A (no, names, no embarrassment - although it is most definately deserved):
SqlDataAdapter dad = new SqlDataAdapter("Select * from esrdat where esrdat_date between '" + Convert.ToDateTime(dateTimePicker1.Value) + "' and '" + Convert.ToDateTime(dateTimePicker2.Value) + "'", con);
Here, for your delectation we have:
1) Take a valid DateTime
2) Use a default conversion to a string
3) Convert it back to a DateTime
4) Then pass that (converted back to a string via another default conversion) to SQL
But in the local format, rather than anything SQL is expecting, which is ISO format.
Twice.
And it's in Q&A because SQL doesn't like the date format it eventually gets passed...
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
Where's the first conversion? Is dateTimePicker.Value not a DateTime?
By the way I hope you answered the question as well as posting it here because that seems like newbie ignorance that deserves illumination.
|
|
|
|
|
You are right, I am wrong - somebody went to the work of adding a DateTime convertion routine that accepts a DateTime, and returns it, unchanged! (I suspect I would have deliberately omitted it, or thrown an exception if you tried to use it, just for being silly)
And yes I did.
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
And let's add not using SQL parameters to avoid most of this to the list
I'm invincible, I can't be vinced
|
|
|
|
|
See? That's one of the problems with giving newbies a "Convert" class; they think they need it all the frickin' time -- they don't learn what it does or what alternatives there are.
|
|
|
|
|
And that's what I always say: Let them learn with an old school single board computer. Take away all fancy frameworks and operating systems and let them discuss things directly with the processor for a while. By the time we give them any compilers, they will already have gotten used to using that grey mass in their heads for other things than keeping the ears apart.
I'm invincible, I can't be vinced
|
|
|
|
|
...Or they run away screaming. win-win
|
|
|
|
|
In my experience, once you turn them into embedded programmers, they always think they have to roll their own. We've got a guy in our group like that. We're constantly having to tell him "No, just use class Mousetrap . Yes, yours is cool and all, but we've got lots of time on Mousetrap , plus it works with the rest of the architecture. No, yours doesn't."
Software Zen: delete this;
|
|
|
|
|
Making database queries in the presentation layer!!
"You get that on the big jobs."
|
|
|
|
|
So this is an approach that proved so successful that it was made into a standard. You're writing a shared library and you're concerned to ensure future compatibility across services. Problems include:
* How to support non built-in types? (e.g. MyCustomType)
* How to support float, int, double, etc?
* How to prevent constantly updating interfaces from complicating builds?
Best approach? Well, how about you convert all your arguments into Strings to transfer across the wire and then convert them back.
Every method has the following signature:
public String[] doSomething(String[] args, String userId)
Then you have a static library that allows:
TypeUtils.stringify(Object object);
Object obj = TypeUtils.fromString(String string, String fromType);
Easy. (Note you may need to cast the object returned from TypeUtils.fromString(). User id is there to ensure security, obviously. You don't have to use the TypeUtils but you are encouraged to, for convenience.
This way, when you swap args[2] and args[3], or when you introduce a new argument at the end, you don't have to declare a new version of the interface.
Simply keep the same version interface jar throughout and require everyone to use the very latest implementation.
This is why I don't program
|
|
|
|