Any way for winsock to return a ping?
Im pinging servers..and ive gotten it to go really fast, but i want to see which ones are the fastest (thus pinging) since im doing it so fast with a for loop i cant use gettickcount since it finishes the loop before it goes to the winsock.getdata..
I hope you get it..im going for speed here, and those ping API's just dont cut it..
Re: Any way for winsock to return a ping?
Re: Any way for winsock to return a ping?
I don't know exactly what you are asking for.
Perhaps you could show some code and illustrate the problem.
Re: Any way for winsock to return a ping?
Well..im using a for next loop to ping a whole bunch of servers:
(psuedo code)
VB Code:
Dim MyStr() as string,M as long,i as long
For i = 0 to ubound(Servers)
MyStr() = Split(Servers(i), ":")
winsock1(m).RemoteHost = mystr(0)
winsock1(m).remoteport = mystr(1)
winsock1(m).senddata "stuff here"
Next i
Now when i get the returns..they dont come back with a ping and i have no way to see what the ping is..
Re: Any way for winsock to return a ping?
What do you mean they don't come back with a ping?
You get a response, right?
Re: Any way for winsock to return a ping?
You can also use the IcmpSendEcho API to do a ping.
Re: Any way for winsock to return a ping?
Quote:
Originally Posted by moeur
What do you mean they don't come back with a ping?
You get a response, right?
yes, but i was using gettickcount or queryperformancecounter before..And now since im using a for next loop they all get sent data, and respond after im done sending to all the servers. I dont want to ping them after word, very time consuming...I dont know how to make it any clearer..
Re: Any way for winsock to return a ping?
so what is the problem? the timing?
You form an array of start times, when responses come in you get an array of stop times.
Re: Any way for winsock to return a ping?
Hi
mayby make a new Thread for each Ping
Chris
Re: Any way for winsock to return a ping?
Quote:
mayby make a new Thread for each Ping
What???
Nooooo....
Re: Any way for winsock to return a ping?
How about if you place a Doevents at the end of Loop
could help that ?
Chris
Re: Any way for winsock to return a ping?
Doevents is a possible solution but it should be used with care. You can easily run into out of stack memory problems if doevents is abused/misused. And it'll consume cpu time from switching.
Are you really doing a "ping" the way most people understand it or (based on the code you provided) are you refering to packets sent by the remote host due to dataarrival event (on the remote host) code? But anyway...
How precise do you need the timing info? seconds? milliseconds? Why not send them by batches and check for results on a given period (say every half second, etc).
So if you had a matrix, you can add one column (a counter) that's updated (every half second) for those IPs still waiting for replies. So an IP sent in the first batch, still has no reply after sending the second batch will have a count of 0.5. If still no reply after the third batch 0.5 is updated to 1 sec delay and so on.
Although a table or collection (so you have a primary key based on IP-port) would be more convenient to use since you can have an element direct update instead of looping through the array again just to update one delay status.
1 Attachment(s)
Re: Any way for winsock to return a ping?
Heres an example (the ips are just random proxies i found)
Re: Any way for winsock to return a ping?
Re: Any way for winsock to return a ping?
You sent data without connecting?
1 Attachment(s)
Re: Any way for winsock to return a ping?
Quote:
Originally Posted by leinad31
You sent data without connecting?
UDP
sorry moeur
Re: Any way for winsock to return a ping?
Of course what you're doing isn't a true ping.
Only the servers you contact on port 80 are responding to your message.
I deleted all winsock controls except 0 then loaded them in the loop.
I put the code into a command button.
Found a few mistakes, try this.
VB Code:
Option Explicit
Private Declare Function GetTickCount Lib "kernel32" ( _
) As Long
Dim iPing(0 To 100) As Long
Private Sub Command1_Click()
Dim Proxies As String, iProx() As String
Dim iStr() As String, L As Long, M As Long
M = 0
Proxies = "148.244.150.58:80,195.14.50.25:3128,195.242.36.3:3128,195.14.50.25:8000,148.244.150.57:80,148.244.150.58:80,195.14.50.25:3128,195.242.36.3:3128,195.14.50.25:8000,148.244.150.57:80,148.244.150.58:80,195.14.50.25:3128,195.242.36.3:3128,195.14.50.25:8000,148.244.150.57:80,148.244.150.58:80,195.14.50.25:3128,195.242.36.3:3128,195.14.50.25:8000,148.244.150.57:80"
iProx() = Split(Proxies, ",")
For L = 0 To UBound(iProx)
iStr() = Split(iProx(L), ":")
If L > 0 Then Load Winsock1(L)
With Winsock1(L)
.RemoteHost = iStr(0)
.RemotePort = iStr(1)
iPing(L) = GetTickCount
.SendData "asdfa"
End With
Next L
End Sub
Private Sub Winsock1_DataArrival(Index As Integer, ByVal bytesTotal As Long)
Dim strData As String
Dim myping As Long
myping = GetTickCount - iPing(Index)
With Winsock1(Index)
Debug.Print Index, .RemoteHostIP & .RemotePort & " " & myping & "ms"
End With
End Sub
Re: Any way for winsock to return a ping?
but if i have like 200 ips..wont loading all those winsocks kill ram or something? Doesnt the winsock control like "leak" into memory when you have so many?
Re: Any way for winsock to return a ping?
I don't think you will leak memory. 200 controls is certainly doable.
If you want to do this with one control then you'll have to do them all sequentially. That is: send message to server, get response, send message to next server, get response,...
Re: Any way for winsock to return a ping?
how about 1000? is that bad?
And for future reference, to reuse the winsock controls:
VB Code:
On Error Goto ErrHndler
If i > 0 And Winsock1(i).Tag <> "" Then Load Winsock1(i)
ErrHndler:
If Err.Number = 340 Then
Resume Next
End If