PDA

Click to See Complete Forum and Search --> : Pinging not working plz help


ViSi0n
Jul 15th, 1999, 03:37 AM
My sub i'm using is

Public Function Ping(szAddress As String, ECHO As ICMP_ECHO_REPLY) As Long

Dim hPort As Long
Dim dwAddress As Long
Dim sDataToSend As String
Dim iOpt As Long
sDataToSend = " Echo This Echo This Echo This"
dwAddress = AddressStringToLong(szAddress)
Call SocketsInitialize
hPort = IcmpCreateFile()
If IcmpSendEcho(hPort, dwAddress, sDataToSend, Len(sDataToSend), 0, ECHO, Len(ECHO), PING_TIMEOUT) Then
'the ping succeeded,
'.Status will be 0
'.RoundTripTime is the time in ms for
'the ping to complete,
'.Data is the data returned (NULL terminated)
'.Address is the Ip address that actually replied
'.DataSize is the size of the string in .Data
Ping = ECHO.RoundTripTime
Else: Ping = ECHO.status * -1
End If

Call IcmpCloseHandle(hPort)
Call SocketsCleanup
End Function

and my code is:
Dim O As Variant
Dim ECHO As ICMP_ECHO_REPLY
For O = 0 To Openr.List1.ListCount - 1
Openr.List1.ListIndex = O
Openr.StatusBar1.SimpleText = "Pinging: " + Openr.List1

Call Ping(Openr.List1, ECHO)

Openr.Text1 = ECHO.RoundTripTime & " ms"

If Openr.Text1.text = "0 ms" Then Openr.Text1.text = "Timeout"

but it doesn't seem to be pinging, unless i'm in the development environment.

Aaron Young
Jul 17th, 1999, 09:30 AM
Are you getting a Division By Zero error when you run your compiled EXE?

Try changing the Project Properties Compile Section to No Optimization and it should work fine, the only thing I can think of is some error trapping is sacrificed for speed when the compiled code is optimized.


------------------
Aaron Young
Analyst Programmer
aarony@redwingsoftware.com
adyoung@win.bright.net

ViSi0n
Jul 18th, 1999, 02:31 AM
Damn your the man Aaron, and you are right the pinging becomes very very slow. Are there no ways to speed it up like how it works in the Development Environment?