1

I'm confused..

I'm using XAMPP in my PC to create a local server that has a few php scripts that connects to a mysql database (also on my local server) and receive data and then send this data to my android application..

My question is about the android app, what IP should I give in the HttpPost to connect my PC and access the php script ?

Should I use the IP of my machine followed by the :port and the path to the php file or should I use only 10.0.2.2 and the path to the file ? I pretend to test this app in my real device, not in emulator.

yat0
  • 967
  • 1
  • 13
  • 29
  • "Android connect to localhost PC" - a contradiction in terms! "localhost" == "software loopback address" for *the same host*! – paulsm4 Nov 19 '13 at 00:20
  • I'm sorry for the confusion.. @paulsm4 – yat0 Nov 19 '13 at 00:21
  • See also this link: [How can I access my own localhost from my Android Device?](http://stackoverflow.com/questions/4779963/how-can-i-access-my-localhost-from-my-android-device/). – paulsm4 Nov 19 '13 at 00:25

1 Answers1

1

If your android device and local computer are on same wifi router, you can run ipconfig (windows) or ifconfig (linux) to have the IP address of your computer on the network of the router (generally wtarting with 192.168.x.x)

You should use this IP address to connect from your Android device to your computer.

Note : Be sure your ports are open on your computer to let the phone connect to your computer

  • thanks! I've seen a tutorial that used that 10.0.2.2, so I was making confusion.. I think this 10.0.2.2 it's used when we are testing in emulator, am I wrong ? – yat0 Nov 19 '13 at 00:25