How To: Use the Ping class

Networking In The Hand includes the Ping class (In the InTheHand.Net.NetworkInformation namespace). The component allows you to determine if a network path to a particular host is available and whether the host is responding. It doesn’t guarantee that a particular service is running on the server (HTTP, FTP etc). You can perform a Ping in a couple of lines of code, the class has been designed to be an exact subset of the equivalent class in the full .NET framework. The following is an example of the simplest ping request using a default payload and timeout settings.

InTheHand.Net.NetworkInformation.Ping p = new InTheHand.Net.NetworkInformation.Ping();
InTheHand.Net.NetworkInformation.PingReply reply = p.Send(“www.google.com”);


if (reply.Status == IPStatus.Success)
{
   string message = string.Format(“Address: {0}rnRoundTrip time: {1}rnTime to live: {2}rnDon’t fragment: {3}rnBuffer size: {0}”,
      reply.Address.ToString(),
      reply.RoundtripTime,
      reply.Options.Ttl,
      reply.Options.DontFragment,
      reply.Buffer.Length);

   MessageBox.Show(message, “Ping”);
}
else
{
   MessageBox.Show(reply.Status.ToString(), “Ping”);
}


The class allows you to further customise the request. You can specify your own data payload for example, or set a different timeout value (the default is 5 seconds).

How To: Use the AuthenticationDialog

Networking In The Hand 2.0 offers a new dialog which allows you to prompt the user for networking credentials. The dialog is designed for the best appearance depending on your platform, for example the screenshots below show both Windows Mobile 5.0 Pocket PC and Windows Mobile 6 Standard Landscape:-


 


   


If your application stores authentication details you can pre-populate the dialog. Optionally you can display a Save Settings checkbox on the form. The following code snippet shows how to display the dialog and return the credentials as an ICredentials object:-


private ICredentials GetCredentials(string resourceName)
{
   InTheHand.Windows.Forms.AuthenticationDialog ad = new InTheHand.Windows.Forms.AuthenticationDialog();


   ad.ResourceName = resourceName;
   if(ad.ShowDialog() == DialogResult.OK)
   {
        return new NetworkCredential(ad.Username, ad.Password, ad.Domain);
   }
   else
   {
      return null;
   }


}