Network Connection detection program using C ++ Builder

Source: Internet
Author: User

In Windows, we often use ping.exe to test network connectivity. The Ping implementation process is very simple. This command will cause the IP layer to send a simple IP packet, usually 32 bytes. After receiving the package, the target party changes the source address and destination address, and resends the package. Of course, some timeout mechanisms need to be added. In fact, we can also use the NMEcho control in the C Builder NetMaster to implement the network connection detection function. First, define the following controls: Three Edit controls: one for receiving the IP address or domain name of the remote host, one for receiving the time-out mechanism set by the user, and the other for setting the port number. Two RichEdit controls: one for sending information to the remote host and the other for receiving information from the remote host. Two CheckBox controls: whether to set the port number. A Button control: used for testing. A StatusBar control is used to display the application status. The program implementation code is as follows: void _ fastcall TForm1: Button1Click (TObject Sender) {// sets the standard TCP/IP attribute NMEcho1-> Host = Edit1-> Text of the NMEcho control; NMEcho1-> TimeOut = StrToInt (Edit2-> Text); if (CheckBox1-> Checked) NMEcho1-> Port = StrToInt (Edit3-> Text ); else NMEcho1-> Port = 7; // default Port number of Echo in TCP/IP NMEcho1-> ReportLevel = Status_Basic; NMEcho1-> Connect (); // establish the connection RichEdit2-> Clear (); for (int I = 0; I // RichEdit1 is used to send information to the remote host RichEdit2-> Text = Rich Edit2-> Text NMEcho1-> Echo (RichEdit1-> Lines-> Strings [I]); NMEcho1-> Disconnect ();} Note: Connect () method, make sure that the connection has been established before receiving data.

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.