C # Ping Class examples can be used to test the network, host response time, and so on.

Source: Internet
Author: User



This example is used to detect the normal communication between the host and the Ping class. Delay how many milliseconds, etc...

The complete code is as follows:

Introduction of namespaces:

Using System.Net.NetworkInformation;


Complete code:

namespace Pingexample {public partial class Form1:form {public Form1 () {Initializ
        Ecomponent (); } private void Btn_startping_click (object sender, EventArgs e) {this.lst_PingResult.Items.Cl
            Ear (); Remote server IP String ipstr = txt_IPAddress.Text.ToString ().
            Trim ();
            Construct Ping instance Ping Pingsender = new Ping ();
            Ping option to set pingoptions options = new PingOptions (); Options.
            Dontfragment = true;
            Test Data String = "Test Abcabc";
            byte[] buffer = Encoding.ASCII.GetBytes (data);
            Set timeout time int timeout = 120;
            Call the synchronous send method to send the data and save the return result to the pingreply instance pingreply reply = Pingsender.send (ipstr, timeout, buffer, options); if (reply. Status = = ipstatus.success {LST_PINGRESULT.ITEMS.ADD ("host address of reply:" + reply.)
     Address.tostring ());           LST_PINGRESULT.ITEMS.ADD ("Round Trip Time:" + reply.)
                Roundtriptime); LST_PINGRESULT.ITEMS.ADD (Live Time (TTL): + reply.
                OPTIONS.TTL); LST_PINGRESULT.ITEMS.ADD ("Control packet Fragmentation:" + reply.)
                Options.dontfragment); LST_PINGRESULT.ITEMS.ADD ("Buffer size:" + reply.)
            Buffer.length); else Lst_PingResult.Items.Add (reply.
        Status.tostring ());
 }
    }
}


If the above code is not compiled, you can download the complete example to the following address:


http://download.csdn.net/source/3464606

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.