Troubleshooting of connection refused exception when connecting Android real machine to PC Server

Source: Internet
Author: User

Connection refused exception occurs when I use an android real machine to connect to the PC server to download files.

After checking, the problem is solved because the mobile phone is not connected to the computer's wifi network (network sharing) and the mobile phone can use the computer's wifi network to connect to the network normally.

Note that the mobile phone and computer must be in a LAN and use the lan ip address of the computer, for example, 192.168.1.xxx: 8080 (pc ip address)/xxxx to access the computer.

This error leads to a problem:

Determine whether the network is connected to the function code:

Connectivitymanager = (connectivitymanager) Context
. Getapplicationcontext (). getsystemservice (
Context. connectivity_service );
If (Manager = NULL ){
Return false;
}
Networkinfo = manager. getactivenetworkinfo ();
If (networkinfo = NULL |! Networkinfo. isavailable ()){
Return false;
}
Return true;

The code above checks whether the network is connected. I found a problem.

In fact, this function can only determine whether the network is enabled. For example, if the Wi-Fi network switch on the mobile phone is enabled, this Code considers network connection as a matter of fact. For example, if we connect to CMCC, although connected (WiFi enabled) however, you still cannot access the Internet (you need to enter the user name and password on the webpage, you know ), therefore, this function is not accurate. It can only be used to determine whether the network is opened or not. However, in many cases, if a user opens a connection, the network connection will be guaranteed) there should be few cases where WiFi is turned on and then no network connection (for example, if a user does not access the Internet, but the user is a Tom and does not know that he has enabled the Wi-Fi connection ).
In fact, this accuracy issue is acceptable.

 

I think the best way to determine whether the network is connected is to ping www.baidu.com to check the return value, but I have not tried it yet.

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.