How does windowmobile determine whether the network is connected or whether the WebService server address is correct (whether WiFi is enabled or not)

Source: Internet
Author: User

In windowmobile development, if the network is not connected successfully or the server address is incorrect, the software will crash when the program calls the WebService method.

There are the following solutions:

1. Download the server-specific static HTML to see if the download is successful. If the download is successful, the network is smooth.

1 // test whether the network connection is normal 2 Private bool testnet () 3 {4 try 5 {6 httpwebrequest request = (httpwebrequest) webrequest. create ("http: //" + textbox1.text + @ "/webtest.htm"); // a static html file address above the Server 7 Request. timeout = 10000; // connection timeout 8 webresponse response = request. getresponse (); 9 stream = response. getresponsestream (); 10 encoding = encoding. getencoding ("gb2312"); 11 streamreader reader = new strea Mreader (stream, encoding); 12 string result = reader. readtoend (); 13 reader. close (); 14 if (result. contains ("eluxianfeng") // static file content 15 {16 MessageBox. show ("server connection successful! "); 17 return true; 18} 19 else20 {21 MessageBox. Show (" server connection failed! Check whether the server address and port are correct! "); 22 return false; 23} 24} 25 catch (exception E1) 26 {27 statictools. wirtelog ("Test on server address:" + e1.message + e1.stacktrace); 28 MessageBox. show ("the server did not respond! Check whether the server address is correct or whether the network is connected! "); 29 cursor. Current = cursors. Default; 30 return false; 31} 32}

 

2. Directly determine whether WiFi is enabled (because the program is used for LAN ).

Using a namespace:

1 using Microsoft.WindowsMobile.Status;
// Test the connection private void button3_click (Object sender, eventargs e) {bool islineon = systemstate. wifistateconnected; // If (! Islineon) // if the network is not smooth {MessageBox. Show ("the network is not connected, check whether the network is smooth! "); Return;} cursor. current = cursors. waitcursor; // set the cursor to the waiting state testnet (); // download the specified static file cursor. current = cursors. default; // restore the initial state of the cursor}

 

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.