Results 1 to 7 of 7

Thread: ping.send and timeout issues

  1. #1

    Thread Starter
    Member
    Join Date
    Jun 2008
    Posts
    37

    ping.send and timeout issues

    OK, What I am trying is a very basic "Ping" but it seems to ignore the timeout value I set in the ping.send overload...

    vb.net Code:
    1. Imports System.Net
    2. Imports System.Net.NetworkInformation
    3.  
    4. Dim ping As New Ping
    5. Dim intTimeout As Integer = 200
    6. Dim reply as PingReply = ping.Send("192.168.12.200", intTimeout)
    7. Dim q As Integer = reply.RoundtripTime
    8. Console.WriteLine(q & " " & intTimeout)
    9.  
    10. Select Case reply.Status
    11.     Case IPStatus.TimedOut
    12.         Console.WriteLine(reply.Status.ToString)
    13.     Case IPStatus.Success
    14.         Console.WriteLine("Success")
    15.     Case Else
    16.         Console.WriteLine(reply.Status.ToString)
    17. End Select

    That should be that if it takes longer than 200ms it is classed as a "Time Out" and returns 0 for the ping time, however it replies as a success when the ping time is greater than the timeout value.

    Note: the cases are there with the code snipped as they are not relevant because it always passes into the "success" category.

    Any ideas? I have tried using Async pings too, but they produce the same result...

    Cheers,

    Stu

  2. #2
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: ping.send and timeout issues

    that is what it does, and always has done. the command line ping does the same thing. if you dig around MSDN you will find the answer as to why (i used to have it, but can't seem to find it).
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  3. #3
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: ping.send and timeout issues

    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  4. #4

    Thread Starter
    Member
    Join Date
    Jun 2008
    Posts
    37

    Re: ping.send and timeout issues

    When specifying very small numbers for timeout, the Ping reply can be received even if timeout milliseconds have elapsed.
    Any idea what constitues a "very small number" as 250ms doesn't seem all that small to me. Looks like I may have to use Async with my own implementation if it can't be as small as that...

  5. #5
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: ping.send and timeout issues

    yes, that is a small timeout, and so is 1. why is it important? i chased this once and just ended up frustrated.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  6. #6

    Thread Starter
    Member
    Join Date
    Jun 2008
    Posts
    37

    Re: ping.send and timeout issues

    There are probably better ways around it, but we have some sort of issue with users and DCs over client and site-to-site VPN connections whereby we get random and sporadic disconnects. I was hoping to be able to take the standard Microsoft ping client and increase the frequency to more than 1 per second. This then would be installed on a server in each site and started synchronously by adding a listening socket for a "go" command to try and get an overview of latency and the such over the VPN links.

  7. #7
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: ping.send and timeout issues

    another rough idea

    Code:
    Imports System.ComponentModel, System.Net.NetworkInformation, System.Threading
    Public Class Form1
        Dim WithEvents pinger As New BackgroundWorker
        Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
            pinger.CancelAsync()
        End Sub
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            pinger.WorkerReportsProgress = True
            pinger.WorkerSupportsCancellation = True
            pinger.RunWorkerAsync()
        End Sub
        Dim tmo As Integer = 1000
        Dim sent, good, bad As Long
        Dim rtt As Double, avgRTT As Long, swRTT As Long
        Private Sub pinger_DoWork(ByVal sender As Object, _
                                  ByVal e As System.ComponentModel.DoWorkEventArgs) _
                                  Handles pinger.DoWork
            Dim aPing As New Ping, reply As PingReply, stpw As New Stopwatch
            rtt = 0
            Do
                stpw.Start()
                reply = aPing.Send("192.168.1.1", tmo)
                swRTT = stpw.ElapsedMilliseconds 'alternative time
                stpw.Stop()
                sent += 1
                Select Case reply.Status
                    Case IPStatus.Success
                        rtt += reply.RoundtripTime
                        good += 1
                    Case Else
                        bad += 1
                End Select
                avgRTT = CLng(rtt / sent)
                If swRTT < tmo Then Thread.Sleep(CInt(tmo - swRTT))
            Loop While Not pinger.CancellationPending
        End Sub
    End Class
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

Tags for this Thread

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