|
-
Jun 10th, 2007, 08:12 PM
#1
Thread Starter
Addicted Member
[2005] Checking if online?
Basically I need an Event for when your internet connection goes on, and off
Or just a way to detect if its on or off, my game will use a chat & a mySQL database, and basically you can't play without internet connection
So, does anyone know how? and if so give an example please and thankyou
-
Jun 11th, 2007, 12:00 AM
#2
Re: [2005] Checking if online?
you could use this API function
Code:
Public Declare Function InternetGetConnectedState Lib "wininet.dll" (ByRef lpdwFlags As Integer, ByVal dwReserved As Integer) As Integer
'FLAGS
'Modem is busy.
Public Const ModemConnectionIsBusy As Integer = &H8S
'Internet connection is currently Offline
Public Const InternetIsOffline As Integer = &H20S
'Internet connection is currently configured
Public Const InternetConnectionIsConfigured As Integer = &H40S
'Internet connection VIA Modem.
Public Const ModemConnection As Integer = &H1S
-
Jun 11th, 2007, 12:41 AM
#3
Re: [2005] Checking if online?
You could, but they only work for dialup and VPN connections. If you're connected through a router, like just about all DSL and cable connections, you need to ping an external host.
However, since you're accessing a server over the 'net anyway, just assume that it's going to be online, and add some code to trap a connection failure. How you do this depends on how you are connecting in the first place.
-
Jun 11th, 2007, 01:44 AM
#4
Thread Starter
Addicted Member
Re: [2005] Checking if online?
How can I ping a site, like google, lol
-
Jun 11th, 2007, 01:57 AM
#5
Re: [2005] Checking if online?
-
Jun 11th, 2007, 02:01 AM
#6
Fanatic Member
Re: [2005] Checking if online?
vb Code:
dim pingSender as New Ping()
dim reply as pingReply = pingSender.Send("www.google.com")
if reply.status = IPStatus.Success then
'success
else
'failure
end if
-
Jun 11th, 2007, 02:04 AM
#7
Re: [2005] Checking if online?
 Originally Posted by Icyculyr Fr0st
How can I ping a site, like google, lol
There's no need. Aren't you accessing a remote host anyway? You don't have to manually check whether the connection is still present, just carry on as if it were and your program flow should handle the case when it isn't.
-
Jun 11th, 2007, 02:32 AM
#8
Thread Starter
Addicted Member
Re: [2005] Checking if online?
Yes, but I wont be setting up the mySQL database for a while, therefore I need something that can check for a net connection
ping, ping reply, and ip status, dont show up as classes to choose from (it gives errors saying they're not aswell)
should I include something? (what should I?)
-
Jun 11th, 2007, 02:38 AM
#9
Re: [2005] Checking if online?
If you don't have anything to connect to then why do you need to check whether you can connect to it?
I'm sorry but I can't see the problem.
-
Jun 11th, 2007, 02:40 AM
#10
Re: [2005] Checking if online?
Carefull with "dim reply as pingReply = pingSender.Send("www.google.com")"
because if you don't have a network enabled it generates an exception so you must do a try catch in any of the solutions.
Ping , pingreply is on the Net.NetworkInformation namespace
-
Jun 11th, 2007, 04:41 AM
#11
Thread Starter
Addicted Member
Re: [2005] Checking if online?
I dont know how to import namespaces so they're being used in my script
I also dont know how to use Try... Catch
Can anyone give an example of both problems, thanks
If you don't have anything to connect to then why do you need to check whether you can connect to it?
I'm sorry but I can't see the problem.
The problem is very very soon you will need connect to something, therefore, I am asking before I need it, so I know how
-
Jun 11th, 2007, 04:50 AM
#12
Fanatic Member
Re: [2005] Checking if online?
for import namesapce use the imports instruction at the very beginning of your class
vb Code:
try
'your work here
catch ex as exception
'something when wrong here
end try
-
Jun 11th, 2007, 04:51 AM
#13
Re: [2005] Checking if online?
I dont know how to import namespaces so they're being used in my script
Just put this statement at the top of your form, the ping code will work then:
vb Code:
Imports System.Net.NetworkInformation
As for not knowing how to use Try/Catch, that's where MSDN really comes in handy, loads more info than I could give. Just look it up. It's not difficult to understand the Try/Catch block.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|