Hi all,
How would one test for internet connectivity in VB.NET instead
of using the Win32 API methods?
Thanks,
Adam 10 2502
WebRequest
T
Adam Honek wrote: Hi all,
How would one test for internet connectivity in VB.NET instead of using the Win32 API methods?
Thanks, Adam
What namespace is this?
..net??
Adam
"tomb" <to**@technetcenter.com> wrote in message
news:bs*******************@bignews3.bellsouth.net. .. WebRequest
T
Adam Honek wrote:
Hi all,
How would one test for internet connectivity in VB.NET instead of using the Win32 API methods?
Thanks, Adam
Adam,
Pinging the first IP address outside your own environment is the way as is
always used with or withouth a program.
Cor
"Adam Honek" <Ad*******@Webmaster2001.freeserve.co.uk> schreef in bericht
news:eK**************@TK2MSFTNGP04.phx.gbl... Hi all,
How would one test for internet connectivity in VB.NET instead of using the Win32 API methods?
Thanks, Adam
Yes I realise it's done via ICMP but I thought .NET has its own method
to check it without employing specialised techniques.
Adam
"Cor Ligthert [MVP]" <no************@planet.nl> wrote in message
news:uL****************@TK2MSFTNGP05.phx.gbl... Adam,
Pinging the first IP address outside your own environment is the way as is always used with or withouth a program.
Cor
"Adam Honek" <Ad*******@Webmaster2001.freeserve.co.uk> schreef in bericht news:eK**************@TK2MSFTNGP04.phx.gbl... Hi all,
How would one test for internet connectivity in VB.NET instead of using the Win32 API methods?
Thanks, Adam
On Tue, 9 May 2006 23:40:26 +0100, "Adam Honek"
<Ad*******@Webmaster2001.freeserve.co.uk> wrote: Hi all,
How would one test for internet connectivity in VB.NET instead of using the Win32 API methods?
Thanks, Adam
If you want to know if a user is able to connect to the internet:
Dim isAvailable As Boolean
isAvailable = My.Computer.Network.IsAvailable
False = user has no current network connection of any kind
True = user is connected to a network of some sort, but doesn't
necessarily mean the internet is reachable.
The companion statement to the above is:
My.Computer.Network.NetworkAvailabilityChanged
I usually do the above at startup in (MyApplicationEvents).
Whether or not you use the above, each attempt to reach a server
should use WebRequest and a Try/Catch Block where you are looking for
a response of "OK" (200). If there is a problem, you would interpret
the exception message which could be "No Connection", "Not
Authorized", "Timeout" etc.
There are WebRequest examples in the help file if you need them.
Gene
I've done what you suggest with WebRequest but it seems it's quite
a thread hog if it's called every second. Unless I put it in its own thread
the UI thread is visibly interupted.
Hmmm, maybe instead of pinging a website it pinged the NIC default IP
gateway on one's PC, this would give better performance?
Nice method though, quick and easy.
Adam
"gene kelley" <ok**@by.me> wrote in message
news:vu********************************@4ax.com... On Tue, 9 May 2006 23:40:26 +0100, "Adam Honek" <Ad*******@Webmaster2001.freeserve.co.uk> wrote:
Hi all,
How would one test for internet connectivity in VB.NET instead of using the Win32 API methods?
Thanks, Adam
If you want to know if a user is able to connect to the internet: Dim isAvailable As Boolean isAvailable = My.Computer.Network.IsAvailable
False = user has no current network connection of any kind True = user is connected to a network of some sort, but doesn't necessarily mean the internet is reachable.
The companion statement to the above is: My.Computer.Network.NetworkAvailabilityChanged
I usually do the above at startup in (MyApplicationEvents).
Whether or not you use the above, each attempt to reach a server should use WebRequest and a Try/Catch Block where you are looking for a response of "OK" (200). If there is a problem, you would interpret the exception message which could be "No Connection", "Not Authorized", "Timeout" etc.
There are WebRequest examples in the help file if you need them.
Gene
Adam Honek wrote: Hmmm, maybe instead of pinging a website it pinged the NIC default IP gateway on one's PC, this would give better performance?
The default gateway is not necessarily outside the LAN. Neither is(are) the
DNS Server(s).
E.g. C:\>ipconfig
Windows IP Configuration
Ethernet adapter Local Area Connection:
IP Address. . . . . . . . . . . . : 192.168.123.14
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . : 192.168.123.1 <-firewall appliance
Andrew
On Wed, 10 May 2006 08:30:38 +0100, "Adam Honek"
<Ad*******@Webmaster2001.freeserve.co.uk> wrote: I've done what you suggest with WebRequest but it seems it's quite a thread hog if it's called every second. Unless I put it in its own thread the UI thread is visibly interupted.
Hmmm, maybe instead of pinging a website it pinged the NIC default IP gateway on one's PC, this would give better performance?
Nice method though, quick and easy.
Adam
I'm not sure what you mean by "called every second". Here is a snip
of something I use. When the execution gets to this point, it's
either a valid response, or there was an exception. On a broadband
connection, here, from the time the URL is selected until the picture
is completely displayed is generally 2-3 seconds. Exceptions other
than timeout are virtually instaneous.
(Code is used in a BackgroundWorker component, DoWork event)
Try
Dim request As HttpWebRequest =
DirectCast(WebRequest.Create(PicLoc), HttpWebRequest)
request.Timeout = 10000
Dim response As HttpWebResponse =
DirectCast(request.GetResponse(), HttpWebResponse)
If response.StatusDescription = "OK" Then
RequestStatus = True
End If
response.Close()
Catch ex As WebException
Select Case ex.Status
Case WebExceptionStatus.ConnectFailure
Case WebExceptionStatus.Timeout
Case WebExceptionStatus.ProtocolError
Case Else
end select
End Try
Gene
Yup so yours is not running in the same time slice as the UI is. On mine
it's currently running this way hence there's this lag in moving the window
or even clicking through the menus.
That above is why I have a threading question posted in this newsgroup.
Thanks,
Adam
"gene kelley" <ok**@by.me> wrote in message
news:rd********************************@4ax.com... On Wed, 10 May 2006 08:30:38 +0100, "Adam Honek" <Ad*******@Webmaster2001.freeserve.co.uk> wrote:
I've done what you suggest with WebRequest but it seems it's quite a thread hog if it's called every second. Unless I put it in its own thread the UI thread is visibly interupted.
Hmmm, maybe instead of pinging a website it pinged the NIC default IP gateway on one's PC, this would give better performance?
Nice method though, quick and easy.
Adam
I'm not sure what you mean by "called every second". Here is a snip of something I use. When the execution gets to this point, it's either a valid response, or there was an exception. On a broadband connection, here, from the time the URL is selected until the picture is completely displayed is generally 2-3 seconds. Exceptions other than timeout are virtually instaneous.
(Code is used in a BackgroundWorker component, DoWork event)
Try Dim request As HttpWebRequest = DirectCast(WebRequest.Create(PicLoc), HttpWebRequest) request.Timeout = 10000 Dim response As HttpWebResponse = DirectCast(request.GetResponse(), HttpWebResponse) If response.StatusDescription = "OK" Then RequestStatus = True End If response.Close()
Catch ex As WebException
Select Case ex.Status Case WebExceptionStatus.ConnectFailure
Case WebExceptionStatus.Timeout
Case WebExceptionStatus.ProtocolError
Case Else
end select
End Try
Gene
Yes.
T
Adam Honek wrote: What namespace is this?
.net??
Adam
"tomb" <to**@technetcenter.com> wrote in message news:bs*******************@bignews3.bellsouth.net ...
WebRequest
T
Adam Honek wrote: Hi all,
How would one test for internet connectivity in VB.NET instead of using the Win32 API methods?
Thanks, Adam This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Cliff Wells |
last post by:
Hi,
I'm writing an application that needs to know if an Internet connection
is available. Basically, I want to have something similar to what a lot
of email clients have, where the app can work...
|
by: Steve Podradchik |
last post by:
Hi,
We have a commercial app that downloads data from various Web pages (not via
a Web Service, per se) and parses the data from the response. The code
below works fine most of the time but, in...
|
by: John Riddle |
last post by:
Hello,
I have an application that runs continously gives an error and stops working
if the internet goes down (which happens for about 5-10 minutes several times
a day. Can anybody tell me how...
|
by: perspolis |
last post by:
Hi all
How can I find that user is connected to internet or not?
thanks in advance
|
by: MLH |
last post by:
If an application sends emails at certain times of the week,
checking internet connectivity before attempting the sends
is something I would like to do.
What's the simplest thing I can do in VBA...
|
by: Ranger |
last post by:
Hi guys, Im new to this site and to vista, but the more I get into it the more I love it.
Ok.. to start off I'll give you the spec's:
Com with internet
Dell e521
Windows Vista Business
USB...
|
by: marsrc |
last post by:
We are developing a wireless device that will need to transmit small amounts of data to an internet server. Although the packet sizes will be small they will be moderately frequent (sent every 10...
|
by: =?Utf-8?B?QnNtZW5nZW4=?= |
last post by:
I am trying to make sure that the local connection is up. I have presently
been using the NetworkChange.NetworkAvailabilityChanged Event for this. Is
there a better way to do this?
Also, I...
|
by: Alexnb |
last post by:
Hello internet.
I am wondering, is there a simple way to test for Internet connection? If
not, what is the hard way :p
--
View this message in context:...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
| |