Can't Connect To Mysql From Android Device
Solution 1:
Solution Intranet/Lan (probably wi-fi):
If your Android Device is on LAN NetWork (probably wi-fi), you have to use the "lan ip".
- Get the ip (local ip/lan ip) of your PC (something like 192.168.1.101 or 10.0.0.101 or 10.1.1.12)
- In your App (on android device) access something like 192.168.1.101:3306
- Tip: recommend setting (manually) the IP of your computer because the router wont change the IP.
For get IP, see:
- Open CMD
- Type "ipconfig" (without quotation marks)
- Press "Enter"
- Your ip, subnet, mask and default gateway will be returned to you
- Copy IP by the line
IPv4 Address: xxx.xxx.xxx.xxx
- Assuming you have returned something like "192.168.1.113"
you must access the address to your "android device" like this:
192.168.1.113:3306
Read about "local ip/Private addresses": http://en.wikipedia.org/wiki/IP_address#IPv4_private_addresses
Note: 10.0.0.1, 10.1.1.1, 192.168.0.1, 192.168.1.1 are IPs privates from ROUTER and non-PC, ie they will never be assigned to other computers because they belong to the router
Emulator:
Running both MysqlServer and Emulator in you computer 127.0.0.1:(port)
The 10.0.2.2 (ie 10.0.2.2:3306) is the solution to that problem.
The emulator runs on a "virtual network", ie is not in the same network as your router.
Emulator Networking details:
- 10.0.2.1 Router/gateway address
- 10.0.2.2 Special alias to your host loopback interface (i.e., 127.0.0.1 on your development machine)
- 10.0.2.3 First DNS server
- 127.0.0.1 The emulated device's own loopback interface
Read: http://developer.android.com/tools/devices/emulator.html
127.0.0.1
127.0.0.1 accesses only the localhost, ie when trying to access localhost with the emulator you try to open own emulator instead of the PC.
Post a Comment for "Can't Connect To Mysql From Android Device"