简体   繁体   中英

How to connect android device to localhost server?

I am trying to establish a connection between my client app running on my android mobile and a server running on my windows 7 PC.

I am new to android and so while looking for some client server tutorial, got the below 2 links.

http://www.compiletimeerror.com/2013/09/creating-java-web-service-using-axis-2.html

http://www.compiletimeerror.com/2013/09/accessing-web-service-from-android.html

Here, server is developed on java and published using axis2 webservice. I followed the tutorial and could develop the similar client and server which runs fine on the emulator. But if I try to access the same using my android mobile it is not working. My mobile is unable to speak to the localhost on my PC.

What I am doing here is,

1. Connected both my PC and mobile to same WIFI network.
2. Connected the mobile to PC using USB.
3. Started the Server on Tomcat
4. Running the Client Project from eclipse and selecting my mobile as target.

Below is my published webservice URL which I am calling from client code,

http://192.168.0.3:8080/MyWebService/services/WebService?wsdl

Here 192.168.0.3 is my PC IP

Please let me know what am I doing wrong here?

Windows 7 might block port 8080. You could test that your port is open from another pc using

telnet 192.168.0.3 8080

or from android using this code .

If 8080 is blocked, then you may want to open it using these steps :

  1. Open Windows Firewall by clicking the Start button Picture of the Start button, and then clicking Control Panel. In the search box, type firewall, and then click Windows Firewall.
  2. In the left pane, click Advanced settings. Administrator permission required If you're prompted for an administrator password or confirmation, type the password or provide confirmation.
  3. In the Windows Firewall with Advanced Security dialog box, in the left pane, click Inbound Rules, and then, in the right pane, click New Rule.
  4. Follow the instructions in the New Inbound Rule wizard.

Note: You must be sure beforehand that your android device is connected to the same local area network or wifi.

Try to access your URL

http://192.168.0.3:8080/MyWebService/services/WebService?wsdl

from your android browser. If you are getting an xml page, then it's not the network problem. If it's network problem, try restarting your local server and changing firewall and router configurations.

You have to provide more information to get a specific answer.

If everything is fine then u should check your Android App. U have to add the following permission for Internet access.

<uses-permission android:name="android.permission.INTERNET"/>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM