Android real machine test connection to local server mobile phone test access to local server Android access through computer

Source: Internet
Author: User

The Android marketplace, developed by myself, started testing on a mobile phone and encountered a problem: "How does an app access the Tomcat server on a local computer on a mobile phone ", if you have some mobile application development experience, you must know that setting "localhost" or "127.0.0.1" is not acceptable. Setting the IP address to "10.0.2.2" on the simulator is accessible, but this method does not work on a real machine.

 

As a result, I began to search for solutions through the Internet in the following ways:

(1) Deploy the application backend server to a server that can be accessed through the public network. The mobile phone can access this public IP address, which is similar to a public network trial.

(2) set the LAN, and the mobile phone accesses a server in the LAN through WiFi (with a lan ip address)

 

Obviously, the above two methods are cumbersome and cannot be quickly switched to the test environment. Previously, I used to share my computer's network to enable my mobile phone to access the Internet, then you must access the Tomcat server on your computer. So it's much easier to switch to the test environment.

 

SolutionYes:
(1) Add an IP address to the local server (my IP address is set to 192.168.0.13)

(2) set the httpclient access address of the Android app to 192.168.0.13.

(3) set the Tomcat host, for example:

(4) Allow the mobile phone to share the Internet of the Local Computer (of course, the mobile phone must be set to debug mode),

Open the application to access the local server. The test passes ~~~~~~

Turn: http://www.chixijiu.com/Item.aspx? Id = 174

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.