XWidgetSoft Forum

XWidget & XLaunchpad , Desktop customization
It is currently May 10th, 2025, 8:19 am

All times are UTC - 8 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Ping to server
PostPosted: January 28th, 2013, 3:11 pm 
Offline

Joined: January 10th, 2013, 6:25 am
Posts: 5
Hi everybody
Is there any possibility to implement a ping to specific server feature to determine whether it is online and time of their response?
Thank you in advance


Top
 Profile  
 
 Post subject: Re: Ping to server
PostPosted: April 28th, 2013, 7:05 pm 
Offline
User avatar

Joined: March 8th, 2013, 10:27 pm
Posts: 353
you can use WMI to do that...

here is some jscript code:

Code:
//good practice to reuse com components
var wmi = GetObject("Winmgmts:");

function Ping(host)
{
   var eStatus = new Enumerator(wmi.ExecQuery("Select StatusCode from Win32_PingStatus Where Address='" + host + "'"));
   if(eStatus.item().StatusCode == 0)
                 {
                          //host reachable
                          //response time
                          var response = eStatus.item().ResponseTime;
                         //do something...
                  }
                 else {
                  //ping failed... server not available
                  }
}

:D

Here is more reference on pinging
http://msdn.microsoft.com/en-us/library/windows/desktop/aa394350(v=vs.85).aspx

_________________
Life is a myriad game... Just play it!


Top
 Profile  
 
 Post subject: Re: Ping to server
PostPosted: April 29th, 2013, 1:00 am 
Offline

Joined: January 10th, 2013, 6:25 am
Posts: 5
Thank you. I've never used WMI before.
Only one thing. Here:
Quote:
var eStatus = new Enumerator(wmi.ExecQuery("Select StatusCode from Win32_PingStatus Where Address='" + host + "'"));

must be '*' instead of 'StatusCode', or ResponseTime will be undefined all time.


Top
 Profile  
 
 Post subject: Re: Ping to server
PostPosted: April 29th, 2013, 4:36 pm 
Offline
User avatar

Joined: March 8th, 2013, 10:27 pm
Posts: 353
Oh! Sorry... my wrong. I never saw that...
I first thought u wanted status code only

_________________
Life is a myriad game... Just play it!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 8 hours


Who is online

Users browsing this forum: No registered users and 16 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  

Powered by phpBB® Forum Software © phpBB Group