|
-
Mar 17th, 2009, 08:00 AM
#1
Thread Starter
Member
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:
Imports System.Net
Imports System.Net.NetworkInformation
Dim ping As New Ping
Dim intTimeout As Integer = 200
Dim reply as PingReply = ping.Send("192.168.12.200", intTimeout)
Dim q As Integer = reply.RoundtripTime
Console.WriteLine(q & " " & intTimeout)
Select Case reply.Status
Case IPStatus.TimedOut
Console.WriteLine(reply.Status.ToString)
Case IPStatus.Success
Console.WriteLine("Success")
Case Else
Console.WriteLine(reply.Status.ToString)
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
-
Mar 17th, 2009, 08:07 AM
#2
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).
-
Mar 17th, 2009, 08:25 AM
#3
Re: ping.send and timeout issues
-
Mar 17th, 2009, 09:46 AM
#4
Thread Starter
Member
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...
-
Mar 17th, 2009, 09:52 AM
#5
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.
-
Mar 17th, 2009, 09:59 AM
#6
Thread Starter
Member
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.
-
Mar 17th, 2009, 12:02 PM
#7
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
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|