Results 1 to 20 of 20

Thread: Any way for winsock to return a ping?

  1. #1

    Thread Starter
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    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..

  2. #2

    Thread Starter
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: Any way for winsock to return a ping?

    anyone?

  3. #3
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    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.

  4. #4

    Thread Starter
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    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:
    1. Dim MyStr() as string,M as long,i as long
    2. For i = 0 to ubound(Servers)
    3. MyStr() = Split(Servers(i), ":")
    4. winsock1(m).RemoteHost = mystr(0)
    5. winsock1(m).remoteport = mystr(1)
    6. winsock1(m).senddata "stuff here"
    7. 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..

  5. #5
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    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?

  6. #6
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Any way for winsock to return a ping?

    You can also use the IcmpSendEcho API to do a ping.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  7. #7

    Thread Starter
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    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..

  8. #8
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    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.

  9. #9
    Junior Member
    Join Date
    Sep 2005
    Posts
    24

    Re: Any way for winsock to return a ping?

    Hi
    mayby make a new Thread for each Ping
    Chris

  10. #10
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    Re: Any way for winsock to return a ping?

    mayby make a new Thread for each Ping
    What???
    Nooooo....

  11. #11
    Junior Member
    Join Date
    Sep 2005
    Posts
    24

    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

  12. #12
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    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.
    Last edited by leinad31; Oct 2nd, 2005 at 10:11 AM.

  13. #13

    Thread Starter
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: Any way for winsock to return a ping?

    Heres an example (the ips are just random proxies i found)
    Attached Files Attached Files

  14. #14
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    Re: Any way for winsock to return a ping?

    can you zip that?

  15. #15
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: Any way for winsock to return a ping?

    You sent data without connecting?

  16. #16

    Thread Starter
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: Any way for winsock to return a ping?

    Quote Originally Posted by leinad31
    You sent data without connecting?
    UDP

    sorry moeur
    Attached Files Attached Files

  17. #17
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    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:
    1. Option Explicit
    2. Private Declare Function GetTickCount Lib "kernel32" ( _
    3. ) As Long
    4.  
    5. Dim iPing(0 To 100) As Long
    6. Private Sub Command1_Click()
    7. Dim Proxies As String, iProx() As String
    8. Dim iStr() As String, L As Long, M As Long
    9. M = 0
    10. 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"
    11. iProx() = Split(Proxies, ",")
    12.     For L = 0 To UBound(iProx)
    13.         iStr() = Split(iProx(L), ":")
    14.         If L > 0 Then Load Winsock1(L)
    15.         With Winsock1(L)
    16.             .RemoteHost = iStr(0)
    17.             .RemotePort = iStr(1)
    18.             iPing(L) = GetTickCount
    19.             .SendData "asdfa"
    20.         End With
    21.     Next L
    22.  
    23. End Sub
    24.  
    25. Private Sub Winsock1_DataArrival(Index As Integer, ByVal bytesTotal As Long)
    26. Dim strData As String
    27. Dim myping As Long
    28. myping = GetTickCount - iPing(Index)
    29. With Winsock1(Index)
    30. Debug.Print Index, .RemoteHostIP & .RemotePort & " " & myping & "ms"
    31. End With
    32.  
    33. End Sub

  18. #18

    Thread Starter
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    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?

  19. #19
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    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,...

  20. #20

    Thread Starter
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    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:
    1. On Error Goto ErrHndler
    2. If i > 0 And Winsock1(i).Tag <> "" Then Load Winsock1(i)
    3.  
    4. ErrHndler:        
    5. If Err.Number = 340 Then
    6.             Resume Next
    7.         End If

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width