Skip to content

Commit

Permalink
Timeout for TCP port ping
Browse files Browse the repository at this point in the history
  • Loading branch information
r-smith committed Jan 19, 2017
1 parent a05a074 commit 3c40a75
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
4 changes: 2 additions & 2 deletions vmPing/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.1.7.0")]
[assembly: AssemblyFileVersion("1.1.7.0")]
[assembly: AssemblyVersion("1.1.8.0")]
[assembly: AssemblyFileVersion("1.1.8.0")]
20 changes: 15 additions & 5 deletions vmPing/Views/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using System.Windows.Input;
using System.Windows.Media.Imaging;
using vmPing.Classes;
using System.Timers;

namespace vmPing.Views
{
Expand Down Expand Up @@ -415,17 +416,26 @@ public void backgroundThread_PerformTcpProbe(object sender, DoWorkEventArgs e)

pingItem.Statistics = new PingStatistics();
int errorCode = 0;



while (!backgroundWorker.CancellationPending && pingItem.IsActive)
{
using (TcpClient client = new TcpClient())
{
++pingItem.Statistics.PingsSent;
DisplayStatistics(pingItem);

try
{
client.Connect(hostname, portnumber);
var result = client.BeginConnect(hostname, portnumber, null, null);
var success = result.AsyncWaitHandle.WaitOne(TimeSpan.FromSeconds(3));

if (!success)
{
throw new SocketException();
}

client.EndConnect(result);

if (backgroundWorker.CancellationPending || pingItem.IsActive == false)
{
pingItem.PingResetEvent.Set();
Expand Down Expand Up @@ -474,12 +484,12 @@ public void backgroundThread_PerformTcpProbe(object sender, DoWorkEventArgs e)
DisplayTcpReply(pingItem, isPortOpen, portnumber, errorCode);
DisplayStatistics(pingItem);
pingItem.PingResetEvent.Set();
Thread.Sleep(5000);
Thread.Sleep(4000);
}

pingItem.PingResetEvent.Set();
}


public void DisplayIcmpReply(PingItem pingItem)
{
Expand Down

0 comments on commit 3c40a75

Please sign in to comment.