Log inUsernamePassword
Log me on automatically each visit    
Register
Register
Log in to check your private messages
Log in to check your private messages
Visual Basic Forum for Visual Basic Programmers VB Forum Index » Communiqué

Post new topic   Reply to topic
Checking Connection to the Net
View previous topic :: View next topic  
Author Message
deathman5
Newbie


Joined: 14 Dec 2003
Posts: 3

PostPosted: Dec 14th, 2003 10:27 AM    Post subject: Checking Connection to the Net Reply with quote

until now this code is the only one which works, I've searched alot alot and never find anything better.
the code down works but it slows the pc down...I want to make a program to check internet connection (through Lan) every second, so this isnt good
I know there alot of codes to check interent connection and fast (but not through Lan)... does anyone have a better code?
is there a better way/code?
please tell me should I keep searching??!

Code:

'Declarations for direct ping
Private Declare Function InternetOpen Lib "wininet.dll" Alias "InternetOpenA" (ByVal lpszAgent As String, ByVal dwAccessType As Long, ByVal lpszProxyName As String, ByVal lpszProxyBypass As String, ByVal dwFlags As Long) As Long

Private Declare Function InternetOpenUrl Lib "wininet.dll" Alias "InternetOpenUrlA" (ByVal hInet As Long, ByVal lpszUrl As String, ByVal lpszHeaders As String, ByVal dwHeadersLength As Long, ByVal dwFlags As Long, ByVal dwContext As Long) As Long

Private Declare Function InternetCloseHandle Lib "wininet.dll" (ByVal hInet As Long) As Long

Private Const INTERNET_OPEN_TYPE_PRECONFIG = 0
Private Const INTERNET_FLAG_RELOAD = &H80000000
Private Const INTERNET_FLAG_KEEP_CONNECTION = &H400000
Private Const INTERNET_FLAG_NO_CACHE_WRITE = &H4000000

Private Function CheckConnectionPing() As Boolean
   Dim sTmp As String
   Dim hInet As Long
   Dim hUrl As Long
   Dim Flags As Long
   Dim url As Variant
   hInet = InternetOpen(App.Title, INTERNET_OPEN_TYPE_PRECONFIG, vbNullString, vbNullString, 0&)
   If hInet Then
      Flags = INTERNET_FLAG_KEEP_CONNECTION Or INTERNET_FLAG_NO_CACHE_WRITE Or INTERNET_FLAG_RELOAD
      hUrl = InternetOpenUrl(hInet, "http://www.yahoo.com/", vbNullString, 0, Flags, 0)
      If hUrl Then
         CheckConnectionPing = True
         Call InternetCloseHandle(hUrl)
      End If
   End If
   Call InternetCloseHandle(hInet)
End Function

Private Sub Form_Load()
MsgBox CheckConnectionPing
End Sub
Back to top
View user's profile Send private message
Blaz3
Guest





PostPosted: Dec 14th, 2003 10:12 PM    Post subject: Reply with quote

Just use the INet ActiveX control then use OpenURL() (I think it's OpenURL), that will return the HTML of where ever you visit.
Back to top
deathman5
Newbie


Joined: 14 Dec 2003
Posts: 3

PostPosted: Dec 15th, 2003 01:00 PM    Post subject: Reply with quote

Blaz3 wrote:

Just use the INet ActiveX control then use OpenURL() (I think it's OpenURL), that will return the HTML of where ever you visit.


can u plz explain more....
how to use openurl()
isnt is the same as my example posted up?
Back to top
View user's profile Send private message
P.T.A.M.
Administrator


Joined: 08 Oct 2003
Posts: 752
Location: Greece

PostPosted: Dec 17th, 2003 10:29 AM    Post subject: Reply with quote

Look here : http://www.avissoft.com/showthread.php?s=&threadid=41
_________________
No one is completely useless. They can at least be an example of what to avoid.
Back to top
View user's profile Send private message Send e-mail Visit poster's website ICQ Number
Blaz3
Guest





PostPosted: Dec 17th, 2003 06:32 PM    Post subject: Reply with quote

deathman5 wrote:

can u plz explain more....
how to use openurl()
isnt is the same as my example posted up?

Ok, no its not the same as yours. You don't need to write all that code :p. Just load the INet control. Here is an example code on how to get an ip address(it goes to a www.no-ip.com page, http://dynupdate.no-ip.com/ip.php)
BTW, if you make the textbox return the inet information like this:
Text1.text = inet1.openurl()
then it adds the html to the text box. since the page at no-ip.com just returns the ip, it returns that in the text box
Code:

'Controls are:
'Command button - cmdClear
'Command button - cmdGet
'Textbox - txtIP
'Inet control - Inet1
Private Sub cmdClear_Click()
    On Error GoTo Error
    txtIP.Text = ""
    Me.Caption = "Ready"
    Exit Sub
Error:
    MsgBox Err.Description, vbCritical, "Error"
End Sub

Private Sub cmdGet_Click()
    On Error Resume Next
    txtIP.Text = Inet1.OpenURL("http://dynupdate.no-ip.com/ip.php")
    Exit Sub
End Sub

Private Sub Form_Load()
    On Error GoTo Error
    Me.Caption = "Ready"
    Exit Sub
Error:
    MsgBox Err.Description, vbCritical, "Error"
End Sub

Private Sub Inet1_StateChanged(ByVal State As Integer)
    On Error GoTo Error
    If State < 10 Then
        Me.Caption = "Working..."
    ElseIf State = 10 Then
        Me.Caption = "Done."
    End If
    Exit Sub
Error:
    MsgBox Err.Description, vbCritical, "Error"
End Sub



Last edited by Blaz3 on Dec 17th, 2003 06:34 PM; edited 1 time in total
Back to top
P.T.A.M.
Administrator


Joined: 08 Oct 2003
Posts: 752
Location: Greece

PostPosted: Dec 18th, 2003 11:47 AM    Post subject: Reply with quote

Cool Wink Add it to the Code Vault Smile
_________________
No one is completely useless. They can at least be an example of what to avoid.


Last edited by P.T.A.M. on Dec 18th, 2003 11:51 AM; edited 1 time in total
Back to top
View user's profile Send private message Send e-mail Visit poster's website ICQ Number
Blaz3
Guest





PostPosted: Dec 18th, 2003 04:27 PM    Post subject: Reply with quote

Ok Smile
Back to top
deathman5
Newbie


Joined: 14 Dec 2003
Posts: 3

PostPosted: Feb 4th, 2004 05:56 AM    Post subject: Reply with quote

I found this code on this site, I got so =D because it works, I can swear it used to work! But now, I dont know why it isnt working.
If I connect to the net, and after connecting to the net I start the program it will detect the connection
but if I start the program and then connect to the net, it wont detect any connection...
why?
plz help

CODE:
Code:

Private Sub Timer1_Timer()
 With Winsock1
   .Protocol = sckTCPProtocol
   .RemotePort = 80
   .RemoteHost = "www.avissoft.com"
   .Connect
   
   Do While .State <> sckConnected And .State <> sckError
     DoEvents
   Loop
   If .State = sckConnected Then
        MsgBox "GO!", vbExclamation
        Timer1.Enabled = False
        Label1.Caption = ""

   End If
   .Close
   .LocalPort = 0
 End With
End Sub
Back to top
View user's profile Send private message
P.T.A.M.
Administrator


Joined: 08 Oct 2003
Posts: 752
Location: Greece

PostPosted: Feb 4th, 2004 10:18 AM    Post subject: Reply with quote

It works for me... What problem are you encountering?
_________________
No one is completely useless. They can at least be an example of what to avoid.
Back to top
View user's profile Send private message Send e-mail Visit poster's website ICQ Number
Display posts from previous:   
Post new topic   Reply to topic    Visual Basic Forum for Visual Basic Programmers VB Forum Index » Communiqué All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Visual Basic Forum runs phpBB | Forum Template © iOptional
VB Resources | SSL | Visual Basic